我想编写一个登录脚本,用户在其中输入电子邮件 ID 和密码,如果电子邮件和密码都正确,则会转到另一个页面。此外,如果电子邮件和密码正确;这些值存储在数据库中。
这是整个更正的工作代码:
<?php
if($_POST['submit']){
$email = protect($_POST['email']);
$password = protect($_POST['password']);
$md5password=MD5($password);
if(!$email || !$password){
echo '<span style="color: red;" /><center>You need to fill in your <b>User Name</b> and <b>Password</b>!</center></span>';
}else{
$res = mysql_query("SELECT * FROM `employer` WHERE `email` = '".$email."'");
$num = mysql_num_rows($res);
if($num == 0){
echo '<span style="color: red;" /><center>The <b>E Mail ID</b> you supplied does not exist!</center></span>';
}else{
$res = mysql_query("SELECT * FROM `employer` WHERE `email` = '".$email."' AND `password` = '".$md5password."'");
$num = mysql_num_rows($res);
if($num == 0){
echo '<span style="color: red;" /><center>The <b>Password</b> you supplied does not match the one for that E Mail ID!</center></span>';}else{
$row = mysql_fetch_assoc($res);
$_SESSION['uid'] = $row['id'];
echo "<center>You have successfully logged in!</center>";
$time = date('U')+50;
mysql_query("UPDATE `employer` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
mysql_query("UPDATE employer (date) VALUES (NOW())");
header('Location: loggedin_employer.php');
}
}
}
}
?>