I have the following table:
ID: bigint autoinc
NAME: varchar(255)
DESCRIPTION: text
ENTRYDATE: date
I am trying to insert a row into the table. It executes without error but nothing gets inserted in database.
try {
$query = "INSERT INTO mytable (NAME, DESCRIPTION, ENTRYDATE) VALUES(?,?,?)";
$stmt = $conn->prepare($query);
$name= 'something';
$desc = 'something';
$curdate = "CURDATE()";
$stmt->bind_param("sss", $name, $desc, $curdate);
$stmt->execute();
$stmt->close();
$conn->close();
//redirect to success page
}
catch(Exception $e) {
print $e;
}
It runs fine and redirects to success page but nothing can be found inside the table. Why isn’t it working?
What about replacing
DESCTIPTIONwithDESCRIPTIONinside the$query?Edit
Just out of curiosity, I created a table called
mytableand copy-pasted your code into a PHP script.Here everything worked fine and rows got inserted, except that the binded parameter
CURDATE()did not execute properly and theENTRYDATEcell was assigned0000-00-00.Are you sure you are monitoring the same database and table your script is supposedly inserting to?
What happens when going with
error_reporting(E_ALL);?Have you verified that the script actually completes the insertion?
The following appears to be working as expected: