0

I am trying to insert data into mysql with mysqli. My connection details are correct, but it will not insert. I've tried with and without backticks.

if ($query = $connection->prepare("INSERT INTO `items` (`user_id`, `name`, `due_date`) VALUES (?, ?, ?)")) {
$query->bind_param('iss', $_SESSION['id'],$_POST['name'],$_POST['dueDate']);
$query->execute(); 


}
TheDizzle
  • 1,534
  • 5
  • 33
  • 76
  • That looks good. Are you sure that `$_SESSION['id']`, `$_POST['name']` and `$_POST['dueDate']` are all set? It may pay to validate those before binding them. – Obsidian Age Jul 11 '18 at 01:51
  • I am positive they are all set. – TheDizzle Jul 11 '18 at 01:53
  • Can you add more checks? See if the bind fails: `if (!$query->bind_param('iss', $_SESSION['id'],$_POST['name'],$_POST['dueDate'])) { echo "Binding parameters failed: (" . $query->errno . ") " . $query->error; }` ... and the same can be done with execute: `if (!$query->execute()) { echo "Execute failed: (" . $query->errno . ") " . $query->error; }` ... you can also add an `else` block to your prepare check as well. Output something like `did not prepare`, or whatever. – Paul T. Jul 11 '18 at 02:26
  • display the error message? [How to get MySQLi error information in different environments](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments) – Ryan Vincent Jul 11 '18 at 06:46

0 Answers0