Reputation: 11
sorry for my bad english. my problem;
$query = $db->prepare("SELECT * FROM user where id = ? and pass = PASSWORD(?)");
$query->execute(array($hes, $pass));
if ($query){
echo "ok";}
else{
echo "empty";}
result: if the password is correct = "ok" if the password is not correct = "ok" How do I fix it?
Upvotes: 0
Views: 323
Reputation: 781300
You're only testing whether the query got an error or not, you're not testing whether it returned any rows. Use:
if ($query->fetch()) {
echo "ok";
} else {
echo "empty";
}
fetch()
returns the next row of the results, which is the first (and presumably only) row in this case. If there's no next row, it returns false
.
Upvotes: 1