SporeDev
SporeDev

Reputation: 608

MySQL update error message

I'm trying to store in MySQL the last date and hour that a user accessed his account. When I log in I get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '16:06:21 WHERE email = 'something@host.com'' at line 1

$query="UPDATE users SET last_visit=$last_visit WHERE email = '$email'";
mysql_query($query) or die (mysql_error());

last_visit is of datetime type.

$last_visit = date("Y-m-d H:i:s");
$email = mysql_real_escape_string($_POST['email']); 

I know that MySQL is depreciated. I'll use MySQLi.

Let me know if I need to edit my question before downrating. Thanks!

Upvotes: 0

Views: 74

Answers (1)

Stephan
Stephan

Reputation: 8090

You forgot the quotes ' since last_visit column is a DATETIME :

$query="UPDATE users SET last_visit='$last_visit' WHERE email = '$email'";

Upvotes: 2

Related Questions