php - Storing the login time in a mysql database -


i'm trying store login time in mysql database. want is..that when user logs in..the script should store current time in table "user" having column "last_seen". last_seen of datetime datatype.

here's code i've written(it's little part of login script..it works after user has enter username , password, , matched in database. :-

$_session['username']=$username; $_session['logged']=1; $date = date('y-m-d h:i:s'); $query = "insert user           (last_seen)           values           ('" . $date . "')           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 error :- have error in sql syntax; check manual corresponds mysql server version right syntax use near 'where user_name = 'test'' @ line 5 (the username of account i'm logging in :- test)

what change code works ?the code store login time of user in db(which later accessed @ backend page).

don't date generation in php. it's easier have

update .... set last_seen=now() ...                           ^^^^^ 

in mysql.

beyond that, insert in no way shape or form accepts where clause.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -