After working with this, it is finally finished. Based on reli4nt's "general advice", I came up with a "precise" method that works for me. In the logging in "if statement", i added the following "CODE". It creates a session variable to store the value of my LastLogin table.
PHP Code:
$LoginRS__query=sprintf("SELECT * FROM tablename WHERE USERNAME='%s' ", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername));
$LoginRS = mysql_query($LoginRS__query, $onpoint) or die(mysql_error());
$query = mysql_fetch_assoc($LoginRS); //My Code
$GLOBALS['LastLogin'] = $query['LastLogin']; //my code
//Session variable for last login
$_SESSION['LastLogin'] = $query['LastLogin']; //My code
This is done when the user clicks on the login button. After that they are redirected to the main page if login is successful.
In the main page I added this code to it:
PHP Code:
$query=mysql_query("UPDATE tablename SET LastLogin=now() WHERE CID='$CID'");
$result = mysql_query($query);
CID='$CID' is a session variable that is created when the page loads. It is used to update the table who's session = the $CID variable. If you had to use this just change the variable to yours and change the database table names to match your database.
What this does it updates the LastLogin table with the current date and time. So if the user closes thier browser or logs out. The next time they login, the time value that was just updated will be displayed in the main info page once they login.
Here is the code i used to echo (display) the time value when the user is redirected to the main info page after loggin in.
PHP Code:
echo date("F d, Y @ g:i a", strtotime($_SESSION['LastLogin']));
This code will display your date variable like this:
December 19, 2005 @ 5:02 pm
Hope this helps.