Jump to content

Recommended Posts

I am trying to update last logged in entry in the database upon succesful login. 

 

I may be way off in the logic here or I may be missing something simple.  I don't get any errors and it logs in fine.  Just does not update the lastvisit field in the database. 

 

 

//record date of most recent login
	$result = mysql_query("SELECT username FROM users WHERE user_id ='".$_SESSION['userId'] . "'"); 
	$dtCreated = date('Y-m-d');
	mysql_query("UPDATE users SET lastvisit=('$dtCreated') WHERE username = $result");

Link to comment
https://forums.phpfreaks.com/topic/237022-help-with-updating-date-in-database/
Share on other sites

mysql_query creates a resource. You're updating where username equals resource id whatever.

 

So:

//record date of most recent login
	$result = mysql_query("SELECT username FROM users WHERE user_id ='".$_SESSION['userId'] . "'"); 
                $theUsername = mysql_fetch_row($result);
                $theUsername = $theUsername[0];
	$dtCreated = date('Y-m-d');
	mysql_query("UPDATE users SET lastvisit=('$dtCreated') WHERE username = $theUsername");

 

Give that a try.

Thanks to both of you, I got it going.

 

Harristweed I thought the same thing as you and had tried that but could not get it to work.

In the end the problem was coming from the fact that when I created the column in the database I did not set it to "not null".  So it would not update the row.  I fixed the null problem and it works great now.

 

Thanks again

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.