Auto update timestamp field
I've tried numerous ways to get the timestamp in the database updated when a user accesses the website by using UPDATE. No matter where I place the code, the timestamp field remains as the initial registration date & time, which at creation was set to timestamp default NULL.
Here's the code that checks to see if the visitor has previously registered and if so, the timestamp should change to the present time.
<?php require_once('Connections/phototest.php'); ?>
<?php
// *** Validate request to login to this site. *****BEGINNING TO TRANSPOSE EARLY DEDDY SITE TO LATEST*******
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck))
{
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['username']))
{
$loginUsername=$_POST['username'];
$password=$_POST['pwd'];
$MM_fldUserAuthorization = "userGroup";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "login_failed.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_phototest, $phototest);
$LoginRS__query=sprintf("SELECT username, pwd, userGroup FROM tbl_users2 WHERE username='%s' AND pwd='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $phototest) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser)
{
$loginStrGroup = mysql_result($LoginRS,0,'userGroup');
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username");
session_register("MM_UserGroup");
if (isset($_SESSION['PrevUrl']) && true)
{
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else
{
header("Location: ". $MM_redirectLoginFailed );
}
}
$query="UPDATE $tbl_users2 SET lastaccesstime = NULL
WHERE username = '$username'";
?>
|