1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)

PHP MySqli Check For No Results in Database

There are many times when you have to PHP MySqli Check For No Results in Database. Maybe you are checking the username and password of a user and match it to an authenticated user.

Prerequisites for PHP MySqli Check For No Results in Database *

In order to perform this query you will have to have something in your database to  compare it to. We are going to compare our form variables to what we have in the database. Make sure that you have the following.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂

Retrieve Information From A Database And Compare *

Here is the code to retrieve information from a database. I included a sample form in this code for you. The important thing to note is that we are using the num_rows; function that comes with PHP. This will tell us if there were no rows that matched the criteria.

<?php include('config.php'); 
if(isset($_POST['submit'])){

$comparethis=$_POST['compare'];
$result = $con->query("SELECT * FROM TABLE WHERE something='$comparethis'") ;

$rowcount = $result->num_rows;

if($rowcount < 1){
echo 'There is no record that matches that';
die()
}

while ($row = $result->fetch_assoc()) {
echo $row['row-name'];
}

$con-> close();
}
?></pre>
<form action="" method="post">
<input name="compare" type="text" />
<input name="submit" type="submit" value="submit" />
</form>
<pre>

 

Subscribe To My YouTube Channel:
PHP MySqli Check For No Results in Database was last modified: March 8th, 2019 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips

Tips

Cool People Share:
PHP Web Development

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.