<?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