0

I find it very hard and i cannot explain why i cannot update a datetime object but when i am inserting a row into the table with the exact same way, it works.

$now= date("Y-m-d H:i:s");
$query = "UPDATE students SET lastvisit=". $now. " WHERE id=4";

I used the exact same way(with $now variable and then pass it into VALUES() ) and the insert statement was successful. Do i have to do it with another way?

will1am
  • 3
  • 1
  • 2
    `$now` is a string, not an integer it needs to be quoted. You should use parameterized queries... or you could use `now()` in the query if the database server and PHP are set for the same timezone. – chris85 Jun 24 '17 at 21:49
  • Also see https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – chris85 Jun 24 '17 at 21:51

0 Answers0