Page 1 of 1

update timestamp for last login

Posted: Mon Oct 05, 2009 11:04 am
by ninethousandfeet
Hi,

I cannot seem to get this update working properly. I am trying to automatically update the user's last login date when they login successfully. This code is automatically executed if the user logs in successfully, but right now it is inserting a blank date into the db (0000-00-00 00:00:00).

Any ideas on what I can do to fix this problem?

Code: Select all

 
$lastLogin = time();
mysql_select_db($database_connectionME, $connectionME);
$strQuery =    "UPDATE userTable SET lastLogin='".$lastLogin."' WHERE username='".$loginUsername."'";
mysql_query($strQuery) or die(mysql_error());
 

Re: update timestamp for last login

Posted: Mon Oct 05, 2009 11:18 am
by N1gel
try

Code: Select all

 
 mysql_select_db($database_connectionME, $connectionME);
 $strQuery =    "UPDATE userTable SET lastLogin=now() WHERE username='".$loginUsername."'";
 mysql_query($strQuery) or die(mysql_error());
 

Re: update timestamp for last login

Posted: Mon Oct 05, 2009 1:05 pm
by ninethousandfeet
perfect, thank you. i kept using quotes around the now() but i didn't even think to just remove them completely.

thank you!

Re: update timestamp for last login

Posted: Mon Oct 05, 2009 1:17 pm
by jackpf
NOW() is a mysql function...so yeah, you don't need quotes around it, otherwise mysql will interpret it as a string.