我現在()函數是tempramental有時它記錄它不會在MySQL有時值。特別是如果我通過輸入用戶名和密碼並按Enter鍵而不是單擊登錄按鈕繞過它。我附上我的代碼。Now()函數是tempratmental
<?php
session_start();
require_once('config.php');
// Retrieve username and password from database according to user's input
$input_username = mysql_real_escape_string($_POST['username']);
$login = mysql_query("SELECT * FROM user WHERE username = '".$input_username."'");
$sql = "UPDATE user SET logindate=NOW() WHERE username='" .mysql_real_escape_string($_SESSION['username'])."'";
mysql_query($sql) or die("Error in SQL: " . mysql_error());
// Check username and password match
$row = mysql_fetch_array($login);
if(mysql_num_rows($login)){
if($row['password'] === md5($_POST['password'])){
$_SESSION['username'] = $_POST['username']; // store in session
} else{
// Invalid login
echo header('Location: loginerror.php');
exit;
}
}
?>
難道你找不到更具描述性的標題嗎?你不能[格式](http://stackoverflow.com/editing-help)你的代碼更好? – 2012-02-12 23:24:10
難道你不認爲這是你引用'$ _SESSION [「用戶名」]'*之前*您設置的問題嗎? – 2012-02-12 23:28:57
你最好檢查$ _ POST已設置得 – MrJ 2012-02-12 23:32:51