Jestem jeszcze zielony w temacie php+msql. I bardzo proszę o podpowiedź.
Chcę zapisać datę ostatniego logowania do kolumny lastlogin. Tu jest struktura mojej bazy oraz dołączam plik logowania.
<?php require_once('Connections/myconn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } $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": break; case "double": break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php require_once('Connections/myconn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } $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": break; case "double": 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. } $loginFormAction = $_SERVER['PHP_SELF']; $_SESSION['PrevUrl'] = $_GET['accesscheck']; } $loginUsername=$_POST['login']; $password=$_POST['password']; $MM_fldUserAuthorization = "active"; $MM_redirectLoginSuccess = "profile.php"; $MM_redirectLoginFailed = "login.php"; $MM_redirecttoReferrer = false; $LoginRS__query=sprintf("SELECT username, password, active FROM userlogin WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); if ($loginFoundUser) { //declare two session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } } else { } } ?> <div id="formularz"> <div align="center"> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Login: <input type="text" name="login" /><br /> Hasło: <input type="password" name="password" /><br /> <input type="submit" value="Zaloguj" /> </p> </div> </div> </form>
CREATE TABLE IF NOT EXISTS `userlogin` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `email` varchar(256) NOT NULL, `dateregister` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `lastlogin` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `active` int(11) NOT NULL DEFAULT '0', `COLOR` varchar(6) DEFAULT NULL, `ip` varchar(15) NOT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `username` (`username`,`email`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=217 ;