Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this php code not send its data to the database?
    primarykey
    data
    text
    <p>I asked a question earlier like this one but I had to change my code a bit and I still do not understand why my database is empty even after I submit an entry. I am new to php and I am following a book where you can find the source code at: <a href="http://www.apress.com/9781430224730" rel="nofollow">http://www.apress.com/9781430224730</a>.</p> <p>after I run the code I do not get an error message but my code does not run the way I want it to and I believe it is because no data is being put to the database which is what the rest of the code relies on.</p> <p>my code where it should be sending data to the database starts on line 66 which I have commented out for you and its next to the else statement.</p> <p>for whatever reason my code just dosent post anything to the database I really appreciate any help</p> <p>here is my code:</p> <pre><code>&lt;?php // Include the functions so we can create a URL include_once 'functions.inc.php'; include_once 'images.inc.php'; //$e = array(); if($_SERVER['REQUEST_METHOD']=='POST' &amp;&amp; $_POST['submit']=='Save Entry' &amp;&amp; !empty($_POST['page']) &amp;&amp; !empty($_POST['title']) &amp;&amp; !empty($_POST['entry'])) { // Create a URL to save in the database $url = makeUrl($_POST['title']); echo "here"; if(isset($_FILES['image']['tmp_name'])) { try { $img = new ImageHandler("/simple_blog/images/");//not in the textbook //print_r($_FILES); //exit; $img_path = $img-&gt;processUploadedImage($_FILES['image']); echo '&lt;img src="', $img_path,'" /&gt;&lt;br /&gt;';//This prints out the image } catch(Exception $e) { die($e-&gt;getMessage()); } } else { $img_path = NULL; } // Include database credentials and connect to the database include_once 'db.inc.php'; $db = new PDO(DB_INFO, DB_USER, DB_PASS); echo "Image Path: ", $img_path, "&lt;br /&gt;"; //exit; in the book but not on the source echo "here"; // Edit an existing entry if(!empty($_POST['id'])) { $sql = "UPDATE entries SET title=?, entry=?, url=? WHERE id=? LIMIT 1"; $stmt = $db-&gt;prepare($sql); $stmt-&gt;execute( array( $_POST['title'], $img_path, $_POST['entry'], $url, $_POST['id'] ) ); $stmt-&gt;closeCursor(); } // Create a new entry else //line 66 { //Save the entry into the database $sql = "INSERT INTO entries (page, title, image, entry, url) VALUES (?, ?, ?, ?, ?)"; $stmt = $db-&gt;prepare($sql); $stmt-&gt;execute(array($_POST['page'], $_POST['title'], $img_path, $_POST['entry'], $url)); $stmt-&gt;closeCursor(); // Sanitize the page information for use in the success URL $page = htmlentities(strip_tags($_POST['page'])); // Send the user to the new entry echo "hopefully we get here"; header('Location: /simple_blog/'.$page.'/'.$url); exit; } } else { header('Location: ../'); exit; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload