我有一个简单的登录页面,顶部是带有 if 和 elseif 语句的简单表单验证。我想将验证代码下方的 mysql select where 语句编写为(elseif)语句。如果邮箱和密码=数据库表记录上的邮箱和密码,那么它会将使用重定向到受保护的页面,如果邮箱或密码不存在或不匹配,最终(else)将显示错误数据库。
我真的不知道如何以正确的方式做到这一点,这是我的尝试,但它不起作用:
<?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>