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.

Link to comment
Share on other sites

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'

 

Link to comment
Share on other sites

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());
?>

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.