这段代码有什么问题?另一种选择是什么?
我没有收到任何错误消息,但每次我输入用户名和密码的组合时,它都会指示我登录页面,即使它是正确的....
$query = $conn->prepare("SELECT * FROM login WHERE username = :username AND password = :password");
$query->bindParam(":username" , $username);
$query->bindParam(":password", $password);
$query->execute();
$result = $query->rowCount();
if($result>0){
header("location:admin.php");
}else{
header("location:login.php");
}
答案 0 :(得分:1)
可能是由于字符集错误;尝试以下步骤:
<meta charset="utf-8" />
。$username = utf8_decode($username);
要测试它,请在代码前写一个print
:
print "SELECT * FROM login WHERE username = '$username' AND password = '$password'"