Jump to content

Help with updating date in database


sac0o01

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
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.