Reputation: 2445
i am trying to add an update which sets the users last activity, at the moment it is just displaying 838:59:59 as the time in the mysql, and i am not quite sure why.
Here is the query i am using on each page to update it.
mysql_query("UPDATE users SET last_activity = ".time()." WHERE user_id = ".$user_id);
Any ideas why i would greatly appreciate
Thanks
Upvotes: 0
Views: 380
Reputation: 19
Really late on this but in case anyone else hits the issue, is userID a number in the example from original question. I made the opposite mistake once, put quote marks around an id that was a number and it took me an embarrassingly long amount of time to figure out why the logout timestamp would not update.
Upvotes: 0
Reputation: 53860
Here's the PHP solution, using UTC (GMT). Make sure you quote the date and other strings:
mysql_query("UPDATE users SET last_activity = '".gmdate('Y-m-d H:i:s')."' WHERE user_id = ".$user_id);
Here it is in local time:
mysql_query("UPDATE users SET last_activity = '".date('Y-m-d H:i:s')."' WHERE user_id = ".$user_id);
You need to format the datetime into the proper format for MySQL.
Upvotes: 0
Reputation: 219864
mysql_query("UPDATE users SET last_activity = CURRENT_TIMESTAMP WHERE user_id = ".$user_id);
Upvotes: 3
Reputation: 2523
mysql_query("UPDATE users SET last_activity = NOW() WHERE user_id = ".$user_id);
Upvotes: 6