0
即使輸入的id
未被識別,$stmt->execute
仍然返回true,因此程序不會輸出「錯誤的ID或密碼!」。我究竟做錯了什麼?
$id = $_POST["id"];
$pwd = $_POST["pwd"];
include("./sql/connect.php");
$stmt = $db->prepare("SELECT * FROM list WHERE id = :id AND pwd = :pwd");
$stmt->bindValue(":id", $id);
$stmt->bindValue(":pwd", $pwd);
if($stmt->execute()){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo $row["name"];
}
}else{
echo "Wrong ID or Password!";
}
爲什麼它應該__not__返回true? –
**永不**存儲純文本密碼。你應該使用['password_hash()'](http://us3.php.net/manual/en/function.password-hash.php)和['password_verify()'](http://us3.php。 net/manual/en/function.password-verify.php)。如果您使用的是5.5之前的PHP版本,請不要**使用MD5或SHA1來散列密碼。相反,您可以使用[此兼容包](https://github.com/ircmaxell/password_compat)。 –
這裏沒有'return' - 只有'echo',你想檢查是否沒有行可能返回? –