I have the following code and I would like to know if mysqli_query
returned any rows and if so return an error.
$result = mysqli_query($connection, "SELECT * FROM users");
if ($result == "") {
echo "No records found";
} else {
echo "There is at least one record in the database";
}
I'm having trouble if the results come back as empty. I've tried using several things and can't figure out how to get it work correctly if nothing is found.
use mysqli_num_rows
like this
if (mysqli_num_rows($result) == 0) {
echo "email was not found";
} else {
echo "email was found";
}
Use mysqli_num_rows to check if any rows were returned or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With