pcw Posted March 17, 2011 Share Posted March 17, 2011 Hi, the code below updates the online field with yes when a user logs in. I also wanted to add the current timestamp to the database eachtime the user logs in. This works fine for updating the online field with yes mysql_query("UPDATE members SET online = 'yes' WHERE username = '$username'"); However when I put it like this, so it updates the timestamp, the logindate field in the database is not updated and a 0 gets placed in the online field? Im really confused at this lol mysql_query("UPDATE members SET online = 'yes' AND logindate = 'CURRENT_TIMESTAMP' WHERE username = '$username'"); Again, any help is much appreciated Paul Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/ Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 Your syntax is off. Replace "AND" with a comma. Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/#findComment-1188699 Share on other sites More sharing options...
pcw Posted March 17, 2011 Author Share Posted March 17, 2011 Hi, thanks for your reply. I have changed the AND to a , Now the online field says yes as it should do, but the timedate in the loggedin field has not changed. How do I fix this? Many Thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/#findComment-1188712 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 Shouldn't be any quotes around the MySQL CURRENT_TIMESTAMP() function . . . "UPDATE members SET online = 'yes' AND logindate = CURRENT_TIMESTAMP() WHERE username = '$username'" Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/#findComment-1188714 Share on other sites More sharing options...
pcw Posted March 17, 2011 Author Share Posted March 17, 2011 great! thanks for yr help again Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/#findComment-1188716 Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2011 Share Posted March 17, 2011 No problem at all. Glad it's working! Quote Link to comment https://forums.phpfreaks.com/topic/230925-update-timestamp-not-working-and-affecting-other-field/#findComment-1188717 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.