SQL是正确的,因为当我在phpMyAdmin中执行SQL时,它给了我正确的输出。下面的代码总是给我输出'指导员'。我该如何解决这个问题?我的if语句的输出总是相同的
queryMysql($query) {
global $conn;
$result = $conn->query($query);
if (!$result) {
die($conn->error);
}
return $result;
}
$usertype = queryMysql("SELECT UserType FROM users WHERE Username='$user' AND Password='$pass'");
$student = 'Student';
$teacher = 'Teacher';
$instructor = 'Instructor';
if ($usertype === $student){
echo 'student';
} elseif ($usertype === $teacher) {
echo 'teacher';
} else {
echo 'instructor';
}
[你的脚本是在对SQL注入攻击的风险。(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –
请使用PHP的[内置函数](http://jayblanchard.net/proper_password_hashing_with_PHP.html)来处理密码安全性。如果您使用的PHP版本低于5.5,则可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。 –
查询返回的结果是什么? –