I am working on a simple login. One piece of logic is that if the username does not exist then they get an error message and they get redirected to a registration page. However when I run my code I keep getting the error described above and no matter what I enter as a username it still comes back as true.
$res = $mysqli->query("SELECT Count(`userID`) FROM `users` WHERE `UserName` = '$username'");
if($res ==0){
return false;
}
else
return true;
}
I control the database as I'm developing it and thus know what usernames are in it. I was under the impression that if I put in a username that was in the database the count would be 1 and thus would return true, likewise if I entered a name that is not in the database then the count would be 0 and thus $res would be false?
You still have to count! The return value of mysqli::query is NOT an integer, it is a result object.
It is considered not the best coding style to verbosely create the return value.
And this leads to the question: What if there are TWO OR MORE rows returned?
It could be done like that: