Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my php code not send its data to the database I have created?
    text
    copied!<p>I am new to php and I have seen a question on this website of someone who had the same problem but the answers to the problem did not help my situation. I can not insert records into my database with my php code.</p> <p>here is my code which I have followed a textbook called 'PHP For Absolute Begginers' by Jason Lengstorf. I can attach the rest of the code in a comment if needed and you can also find the code at this website <a href="http://www.apress.com/9781430224730" rel="nofollow">http://www.apress.com/9781430224730</a> under source code. Where my problem is and where I am supposed to be updating the database starts at line 66 which I commented out to show you next to the else statement:</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']); if(isset($_FILES['image']['tmp_name'])) //line 16 { 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 // 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 problems with the code dont work until after this line { //Save the entry into the database echo"please work this time"; $con = mysqli_connect("localhost","root","","simple_blog"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $page = $_POST['page']; //var_dump($page); $page = mysql_real_escape_string($page); $title = $_POST['title']; //var_dump($title); $title = mysql_real_escape_string($title); $entry = $_POST['entry']; //var_dump($entry); $entry = mysql_real_escape_string($entry); $sql = "INSERT INTO entries(page, title, image, entry, url) VALUES ('$page', '$title', '$img_path', '$entry', '$url')"; mysqli_query($con, $sql); mysqli_close($con); } // 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> <p>Anyone who can tell me why my code does not post to the database I appreciate the help and I thank you.</p>
 

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