When I run this code it only ever returns 0, even when I have the right information. I have checked in the database the same query and it returns a count of one when I have the correct info but this always returns 0.
$query = 'SELECT COUNT(*) FROM user WHERE UserName = "$username" AND UserPass = "$password"';
$result = mysqli_query($con, $query);
$hello = mysqli_fetch_array($result); echo $hello[0]; exit;
change to
$query = 'SELECT COUNT(*) FROM user WHERE UserName = "' . $username . '" AND UserPass = "'. $password .'"';
I really hope you left out your extensive security measures from your snippet. I suggest you apply some prepared statements pronto, but that's a different question!
Instead of using a fetch
, try using num_rows
.
$query = "SELECT 1 FROM `user` WHERE `UserName` = '$username' AND `UserPass` = '$password'";
$result = mysqli_query($con, $query);
echo mysqli_num_rows($result);
Try and play around with something like that!