adamjones Posted October 20, 2008 Share Posted October 20, 2008 Hi. Ok. So on my CMS I want it to show when the user last logged in. At first, I thought about adding this to the 'checklogin.php' (the page where the sessions are set if the login info is correct); <?php $DB_Query = @mysql_query("UPDATE `members` SET Lastlogin=Now() WHERE username=$usersession ") OR die('MySQL error: '.mysql_error()); ?> But I realized that that would just overwrite the last time they logged in with the current time, therefore making it pointless to show when they last logged in as it would be as soon as they hit that 'Login' button - if I'm making sense? So, I was wondering if someone could help? Cheers. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 Before you do the update, select the old value out and keep it in the session with the user data. Quote Link to comment Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Hi. I have this code; <?php $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $lastlogin = $data['lastlogin']; session_register("lastlogin"); $DB_Query = @mysql_query("UPDATE `members` SET lastlogin='Now()' WHERE username=$myusername") OR die('MySQL error: '.mysql_error()); ?> I get the following error; MySQL error: Unknown column 'adam' in 'where clause' Quote Link to comment Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Ahh. Fixed it; I was missing my 's. So now its working, except, on the admin panel where it says "Your last login was on..." It says "Your last login was on Now()". Have I done something wrong? <?php $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $lastlogin = $data['lastlogin']; session_register("lastlogin"); $DB_Query = @mysql_query("UPDATE `members` SET lastlogin='Now()' WHERE username='$myusername'") OR die('MySQL error: '.mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 remove the single quotes from around NOW() Quote Link to comment Share on other sites More sharing options...
adamjones Posted October 20, 2008 Author Share Posted October 20, 2008 Fantastic All working now. Cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.