【发布时间】:2013-12-14 12:21:10
【问题描述】:
我有一些代码有问题,请弄清楚为什么会出错
//Searches the database for the username
$mysqli_username = mysqli_query($mysqli, "SELECT username FROM ajbs_users WHERE username=`".$username."`");
// if name does not exist
if ($mysqli_username == null)
{
echo "<p>Username was inccorect, or user does not exist</p>";
}
else //if username is correct
{
//finds and stores password of the user
$mysqli_userPassword = mysqli_query($mysqli, "SELECT password FROM ajbs_users WHERE password=`".$password."`");
if ($mysqli_userPassword != $password) //checks password matches from user
{
echo "<p>Password was inccorrect</p>";
}
else
{
//Login
echo "<p>You have been logged in";
// Re directs to other page after creating a session
}
}
脚本不断输出“密码不正确”语句。
【问题讨论】:
-
请,使用前请阅读功能说明。只需几次击键:php.net/mysqli_query
-
$mysqli_userPassword包含 MySQL 资源,不是字符串。您正在将结果对象与字符串进行比较,并且比较总是会评估为FALSE。