<?php
session_start();
include 'db.php';
include 'header.html';
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['email'])) {
header("location:profile.php");
} elseif(!empty($_POST['email']) && !empty($_POST['pass'])) {
$email = mysql_real_escape_string($_POST['email']);
$pass = md5(mysql_real_escape_string($_POST['pass']));
$sql = mysql_query("SELECT id, name, email, pass FROM users WHERE email='$email' AND pass='$pass'");
$row = mysql_fetch_array($sql);
$id = $row['id'];
$email1 = $row['email'];
$name = $row['name'];
$num = mysql_num_rows($sql);
if($num == 1) {
$_SESSION['id'] = $id;
$_SESSION['email'] = $email1;
$_SESSION['name'] = $name;
$_SESSION['LoggedIn'] = 1;
$update = mysql_query("UPDATE users SET lastlogin=NOW() WHERE email='$email1'");
header("location:profile.php");
} else {
echo "<h1>Error</h1>";
echo "<p>Sorry! Either your account could not be found or you have entered the wrong email or password. Please try again.</p>";
}
}
?>
此腳本在我的localhost環境中完美工作, profile.php如果會話設置爲或不爲空。有任何想法嗎?php登錄腳本在本地但在主機上不可用
第二個問題,我的代碼是否正確地將'lastlogin'更新爲當前時間?數據庫結構必須爲此做些什麼?它不在我的數據庫中更新。
謝謝你的幫助。
請在腳本的頂部鍵入'error_reporting(E_ALL)'。你會看到至少 – Yang
'NOW()'以這種格式返回日期和時間:「2006-04-12 13:47:36」。我認爲這是你需要的。 –
@metal_fan做到了,但沒有報告錯誤。 FakeHeal謝謝您將繼續測試該部分 – robk27