How to display error message when a row not found in $wpdb?

I want to display a message if a booking ID is found in the $wpdb and want to display another message if the booking ID not found in any row in the database.

So I am using following code:

$booking_ID = $_POST["booking_ID"];
$sql = "SELECT * FROM bookingTBL WHERE booking_ID LIKE '$booking_ID'";
$result = $wpdb->get_results($sql) or die(mysql_error());
if (count($result) > 0){
    echo 'Booking ID <b>'.$booking_ID.'</b>` is found';
    }
else {
    echo 'We could not fint the booking ID <b>'.$booking_ID.'</b><br/>Please refine your booking ID';
}

if a row found with the booking ID then the message Booking ID **GHT65VF** is found is displayed but when there is no row found with the booking ID then it shows blanks. no any messages.

Why is that?

How can I show not found message too when there is no any row with booking ID entered?

Read more here: How to display error message when a row not found in $wpdb?

Leave a Reply

Your email address will not be published. Required fields are marked *