这是用于小型登录和注册程序的代码。每次用户尝试登录此代码时,都会检查电子邮件和密码是否正确。如果在mysql提示符下输入相同的查询,则该查询有效。
我无法弄清楚代码中的错误。每次我输入有效的电子邮件和密码$ result都将变为FALSE。
<html>
<head>
<title>Log In</title>
</head>
<body>
<?php
$host = "localhost";
$user = "root";
$password = "password";
$database = "user";
$conn = mysqli_connect($host, $user, $password, $database);
if(!$conn) {
die("Connection Error: ".mysqli_connect_error($conn));
}
$query = "select email, password from user_info where email = \'$_POST[login_email]\' or password = \'$_POST[login_password]\'";
$result = mysqli_query($conn, $query);
if(!$result)
die("failure");
if(mysqli_num_rows($result) > 0) {
$details = mysqli_fetch_assoc($result);
if($details["email"] != $_POST["login_email"] && $details["password"] != $_POST["login_password"]) {
die("Invalid username or password.");
}
echo "successful";
}
else {
die("Don't have an account yet?. Please Sign Up to get started.");
}
?>
</body>
</html>
最佳答案
@lalithkumar是正确的。但是作为临时解决方案,您可以将$query
行更改为$query = "select email, password from user_info where email = '".$_POST["login_email"]."' or password = '".$_POST["login_password"]."'";
关于php - 我在代码中找不到错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44738606/