Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,195,581 members, 7,958,795 topics. Date: Thursday, 26 September 2024 at 01:12 AM

How To Update Users Last Login Time - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How To Update Users Last Login Time (1481 Views)

How To Login To Wordpress Dashboard And Cpanel Using Simpleserver Or XT181 / Scam Request To Update Visa Account (2) (3) (4)

(1) (Reply) (Go Down)

How To Update Users Last Login Time by deco2come: 12:18am On Apr 21, 2011
I have a users table and lastlogin table. How can I update the last login table with the information from users table. I tried

UPDATE lastlogin SET time = NOW() WHERE ?

I don't know what to write after the WHERE clause since the lastlogin table has only two fields( lastlogin_id and lastlogintime).

The users table has nothing related to the lastlogin table.

If I tried this UPDATE lastlogin SET lastlogintime = NOW() WHERE(SELECT username FROM users WHERE username = $sessionuser);

That means it will keep udating the lastlogin table anytime a different user log in.

How can I keep the last login time of each user?
Re: How To Update Users Last Login Time by Nobody: 2:41am On Apr 21, 2011
This na serious matter o. Please some gurus come and help this guy. I think the problem is that. . .you no sabi code mysql wella.
You need to post your table here for anyone to help you. . .
Re: How To Update Users Last Login Time by yawatide(f): 3:54pm On Apr 21, 2011
If I tried this UPDATE lastlogin SET lastlogintime = NOW() WHERE(SELECT username FROM users WHERE username = $sessionuser);

The above query doesn't make sense. Let's say the username is "larry". What the above translates to is:
UPDATE lastlogin SET lastlogintime = NOW() WHERE(larry);

Now, possible answer (and forgive me in advance for not using the right syntax. I assume you can do that on your own):

I assume that your users table has an auto_increment ID field, say user_id. When the user logs in successfully, you store the username in session, as it seems you have and store the user_id in a var, based on the same select statement that gave you the username. I further assume that your lastlogin_id in the lastlogin table is the secondary key that matches the primary key of user_id of your users table.

Your UPDATE query could then look like this:

UPDATE lastlogin SET lastlogintime = NOW() WHERE lastlogin_id = $variable_you_are_storing_user_id_in

As long as lastlogin_id and user_id match, the timestamp wil be unique for each logged in user

Make sense?
Re: How To Update Users Last Login Time by Nobody: 6:04pm On Apr 21, 2011
Yawa has given it to you already.

i also think your database design needs adjustment.
since the last login table has just 2 columns lastlogin_id and lastlogintime
and you have a user table

it is better and more efficient to have an additional column named lastlogintime in the users table and simply get rid of the last login table

except you have another table named user_info or something similar, that hold details about each user. you can append the new column to that instead, if you like.
Re: How To Update Users Last Login Time by Nobody: 7:44pm On Apr 21, 2011
Errm. Make i go chop bread and beans come back, we go see later tongue

(1) (Reply)

Get .edu, .wiki, .gov. Even .co.uk Backlinks Free / Business Plan Writers For Startups And Smes / Download NAIJALOADED THEME 2019 SEO Optimised Theme

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 25
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.