Wouldn't even workYou must be registered for see links
What do you mean by last login script, are you basically just trying to determine the last time a user logged in? If so that's extremely simple, you could just insert timestamp data into a field called lastlogin on the user's record upon the login script, and then when you wish to output the last login time you simply just format it into the date you want it to be from the timestamp with date("", $timestamp).Wouldn't even work
YEah exactly..aw, can I get a script pls lolWhat do you mean by last login script, are you basically just trying to determine the last time a user logged in? If so that's extremely simple, you could just insert timestamp data into a field called lastlogin on the user's record upon the login script, and then when you wish to output the last login time you simply just format it into the date you want it to be from the timestamp with date("", $timestamp).
Well I basically told you how to do it but here is a very basic method of the script, don't forget you would have to escape the query and such and also link the POST's etc.YEah exactly..aw, can I get a script pls lol
$last = time(); // this is the current time as a timestamp
INSERT INTO users (id, username, password, last)
VALUES ('','$username','$password','$last');
$time = SELECT last FROM users WHERE username = '$username';
date("H:i:s", $time) // this converts the timestamp to a readable date/time
Shit is really confusing for me, see I'm new to PHP & MYSQL so I'm learning... is there a way if you could give me like the whole code tell me where to put it etc?Well I basically told you how to do it but here is a very basic method of the script, don't forget you would have to escape the query and such and also link the POST's etc.
then output it like so:PHP:$last = time(); // this is the current time as a timestamp INSERT INTO users (id, username, password, last) VALUES ('','$username','$password','$last');
readPHP:$time = SELECT last FROM users WHERE username = '$username'; date("H:i:s", $time) // this converts the timestamp to a readable date/time
You must be registered for see linksfor more formatting options of the date/time.
You can't just put all of that in one place lol, if I gave you the whole code I'd have to make the login script as well etc.Shit is really confusing for me, see I'm new to PHP & MYSQL so I'm learning... is there a way if you could give me like the whole code tell me where to put it etc?
Aha, I see but I don't understand 'to the value of time()'You don't even need to create a new table for it. Just add a column called LastLogin or something in your users table
Then when they log in, just do an UPDATE on LastLogin to the value of time()
Then when you want to display it, just do a SELECT from users and use date() to format it
time() in PHP will give you a unix timestamp, if you convert it with date() it will then give you the exact current time in a readable format.Aha, I see but I don't understand 'to the value of time()'
what do you mean by that ?
bruh can we like do this set by step please ? cuz it really gets confusingtime() in PHP will give you a unix timestamp, if you convert it with date() it will then give you the exact current time in a readable format.
Aw, thanks a lot. I'm stuck at the 3rd part lol ... like is there a certain way to do it ?Step 1) Create a new column to hold your Date information
LastLogin is the name of the column, Date is the value, and I always put 0 0 until I know how much information I want it to store, and Not Null because a date column should always have a default value. Upon registery you will satisfy the LastLogin with todays Date.
Step 2) Satisfy the database upon registery
$last = time(); <- As @BIOS explained, time() is a function in PHP that gets the time from your computer and will store that into the variable $last
INSERT INTO users (id, username, password, LastLogin)VALUES ('','$username','$password','$last'); Then you will set LastLogin = the variable $last that you previously set to the time of the computer.
Step 3) Retrieve the information
$LastLoginTime = mysql_query("SELECT LastLogin FROM users WHERE id="'.USER_ID.'" LIMIT 1");
$DateMe = strtotime( $LastLoginTime );
$EchoMe = date('Y-m-d H:i:s', $DateMe);
echo $EchoMe;
It's likely you don't actually have a constant defined as USER_ID. I'm assuming Jay wanted you to change that to whatever variable your user ID is calledAw, thanks a lot. I'm stuck at the 3rd part lol ... like is there a certain way to do it ?
You must be registered for see links, and it displays this :You must be registered for see links. My bad if I i'm being nooby
Duh. He didn't ask that, the reason the above comments are in MySQL is because it's the easiest possible way to show him how to achieve what he's trying to.Please avoid all the above code. mysql_* functions are deprecated. Check out MySQLi or PDO instead.
The MySQL functions are deprecated and, from my understanding, soon be removed from newer versions of PHP so it's best for him to traverse now. But let's not get bogged down in what method to use.Duh. He didn't ask that, the reason the above comments are in MySQL is because it's the easiest possible way to show him how to achieve what he's trying to.
Plus he's fine using MySQL for now with escaping since he's stated he doesn't know much and trying to learn, not to mention he could always upgrade it further on.
Yeah, I think he has started to try MySQLi slightly from what I can see, he is using MySQLi for his connection however for his queries, he's using MySQL. -The MySQL functions are deprecated and, from my understanding, soon be removed from newer versions of PHP so it's best for him to traverse now. But let's not get bogged down in what method to use.