Hello, I have an index page where users enter in username and passwords to get into their account page (called account.php). If login fails, the user is redirected back to index.php
I use php and mysql.
I would like to add a record called "lastlogin" to my "members" table that will be updated with the current date every time someone logs on using the login form on my index page.
How can I achieve this?
Here is my php script:
Here is my form action:Code:<?php require_once(connect.php); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php // *** Validate request to login to this site. if (!isset($_SESSION)) { session_start(); } $loginFormAction = $_SERVER['PHP_SELF']; if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck']; } if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = ""; $MM_redirectLoginSuccess = "account.php"; $MM_redirectLoginFailed = "index.php"; $MM_redirecttoReferrer = false; mysql_select_db($database_connectDB, $connectDB); $LoginRS__query=sprintf("SELECT username, password FROM members WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $connectDB) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = ""; //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); } } ?>
Thank you.Code:<form ACTION="<?php echo $loginFormAction; ?>" id="username" name="form1" method="POST"> <label for="username">Login Username:</label> <input type="text" name="username" id="username" /> <label for="password"><br /> <br /> Login Password:</label> <input type="password" name="password" id="password" /> <input type="submit" name="button" id="button" value="Submit" /> </form>




Reply With Quote