I am trying to insert current date (in d-m-Y) in a prepared statement into mysql table. I can’t get the code right. I am calling current date in php by
$dat = date("d-m-Y");
and then including in a prepared statement like this
$stmt = $mysqli->prepare("INSERT INTO mytable (name, date) VALUES (?, ?)"); $stmt->bind_param('ss', $name, $dat); $reslt = $stmt->execute();
In the table, the date does not get inserted. It remains 0000-00-00. How can I rectify this?
Advertisement
Answer
You should use the YYYY-MM-DD format:
$dat = date("Y-m-d");