I have set dob as type “date” in my html and in my stu table i am taking it as a string so i have made it as varchar, but null is getting stored as default value
Check the code…
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO `stu` (`name`, `gender` , `dob`) VALUES (
?, ?, ? ) "))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
/* Prepared statement, stage 2: bind and execute */
if (!$stmt->bind_param('sss', $name , $gender , $dob )) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
The code you posted is OK (though we can’t see if you actually
execute()the query). The problem is the code that we can’t see, where you define$dob.When you pass
$dobtobind_param()it should be a string, not an object or anything else that you might have. Format$dobas a string and that will enable it to be inserted into the table.I also suggest changing your field to a
DATEinstead of aVARCHAR. Your varchar field will accept any string date format but aDATEfield will needYYYY-MM-DD.