我想編寫一個登錄腳本,用戶輸入電子郵件ID和密碼,並在電子郵件和密碼都正確的情況下轉到其他頁面。 此外,如果電子郵件和密碼是正確的;這些值被存儲在數據庫中。php sql登錄腳本
這裏就是整個校正後的工作代碼:
<?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');
}
}
}
}
?>
給我們展示了一些代碼。 – pixeline
你想喝杯茶嗎? – Benjamin
聽起來像個好主意。我同意。 – Mike