Jump to content

[SOLVED] Making a 'You Last Login Was On...' script.


adamjones

Recommended Posts

Hi.

 

Ok. So on my CMS I want it to show when the user last logged in. At first, I thought about adding this to the 'checklogin.php' (the page where the sessions are set if the login info is correct);

 

<?php
$DB_Query = @mysql_query("UPDATE `members` SET Lastlogin=Now() WHERE username=$usersession ") OR die('MySQL error: '.mysql_error());
?>

 

But I realized that that would just overwrite the last time they logged in with the current time, therefore making it pointless to show when they last logged in as it would be as soon as they hit that 'Login' button - if I'm making sense?

 

So, I was wondering if someone could help?

 

Cheers.

Hi.

 

I have this code;

 

 

<?php
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$lastlogin = $data['lastlogin']; 
session_register("lastlogin");
$DB_Query = @mysql_query("UPDATE `members` SET lastlogin='Now()' WHERE username=$myusername") OR die('MySQL error: '.mysql_error());
?>

 

I get the following error;

 

MySQL error: Unknown column 'adam' in 'where clause'

 

Ahh. Fixed it; I was missing my 's.

 

So now its working, except, on the admin panel where it says "Your last login was on..." It says "Your last login was on Now()". Have I done something wrong?

 

<?php
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$lastlogin = $data['lastlogin']; 
session_register("lastlogin");
$DB_Query = @mysql_query("UPDATE `members` SET lastlogin='Now()' WHERE username='$myusername'") OR die('MySQL error: '.mysql_error());
?>

Archived

This topic is now archived and is closed to further replies.

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