I'm trying to store login time in a mysql database. What I want is..that when a user logs in..the script should store the current time in the table "user" having a column "last_seen". last_seen is of DATETIME datatype.
Here's the code I've written(it's a little part of a login script..it works after the user has enter the username and password, and they are matched in the database. :-
$_SESSION['username']=$username;
$_SESSION['logged']=1;
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO user
(last_seen)
VALUES
('" . $date . "')
WHERE user_name = '" . $username . "'";
mysql_query($query, $db) or die (mysql_error($db));
header('Refresh: 5; URL = main.php');
echo "Login successful, redirecting...";
die();
This throws me the 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 'WHERE user_name = 'test'' at line 5 (The username of the account from which I'm logging in is :- test)
What do I change so the code works ?The code would store the login time of the user in the db(which would be later accessed at a backend page).