update timestamp for last login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

update timestamp for last login

Post 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());
 
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: update timestamp for last login

Post 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());
 
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

Re: update timestamp for last login

Post 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!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: update timestamp for last login

Post by jackpf »

NOW() is a mysql function...so yeah, you don't need quotes around it, otherwise mysql will interpret it as a string.
Post Reply