$NOW = new DateTime();
$date = $NOW->format('Y-m-d'); // return 2018-05-17
I want to update date in database to now date.
Query:
$sql = "UPDATE table SET date = $date WHERE id = $id";
But it update time like this => 0000-00-00
The type of this column is DATE
Why? what I have done wrong?
You can try mysql now() function to update date.
$sql = "UPDATE table SET date = now() WHERE id = $id";
Or you should add single qoutes in query
$sql = "UPDATE table SET date = '".$date."' WHERE id = $id";
Simply add your date value in quotes then try. Change your query to :
$sql = "UPDATE table SET date = '$date' WHERE id = $id";
尝试这个
$sql = "UPDATE table SET `date` = now() WHERE id = '".$id."' ";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.