我有一個簡單的登錄頁面,使用if和elseif命令進行頂級簡單表單驗證。 我想寫一個(elseif)語句作爲驗證代碼下面的mysql select where語句。如果電子郵件和密碼=數據庫表記錄上的電子郵件和密碼,則會將使用重定向到受保護的頁面,如果電子郵件或密碼不存在或匹配,則最後(else)將顯示錯誤數據庫。使用mysql登錄頁面select where statment
我真的不知道如何做到這一點的正確方法,這是我的嘗試,但它不工作:
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
$email = $_POST['Email'];
$hashed_password = md5($_POST['password']);
if (isset($_POST['submit'])) { // Form has been submitted.
if ($_POST['Email'] == "") {
$error = "Email address is required";
}
elseif (!(filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL))) {
$error = "Invalid email address";
}
elseif ($_POST['password'] == "") {
$error = "Type in your password";
}
elseif (strlen($_POST['password']) < 8) {
$error = "Minimum password length is 8";
}
elseif {
$query = "SELECT id, email ";
$query .= "FROM customers ";
$query .= "WHERE email = '{$email}' ";
$query .= "AND hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
redirect_to("account.php");
}
else {
echo "error";
}
}
?>
<!-- signup box -->
<div id="box_sign">
<div class="container">
<div class="span12 box_wrapper">
<div class="span12 box">
<div>
<div class="head">
<h4>Sign In</h4><br />
<div class="text-error">
<?php echo $error; ?><br />
<p class="text-success"><strong><?php echo $success; ?></strong></p>
</div>
</div>
<div class="form">
<form action="sign-in.php" method="POST">
<input type="text" id="Email" name="Email" placeholder="Email"/>
<input type="password" id="password" name="password" placeholder="Password"/>
<div class="right">
<a href="reset.html">Forgot password?</a>
</div>
<input type="submit" name="submit" class="btn" value="Sign In"/>
</form>
</div>
</div>
</div>
<p class="already">Don't have an account?
<a href="signin.html">Sign up</a></p>
</div>
</div>
</div>
redirect_to的()函數我有它在functions.php文件和工作。 – 2013-05-04 13:39:19
'這不起作用?'什麼不起作用?你將不得不更具體些。 – Cyclonecode 2013-05-04 13:40:30
您最終的'elseif'沒有條件。您需要檢查MySQL結果集以查看它是否返回結果。如果是,則重定向。 – Hope4You 2013-05-04 13:41:44