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.

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.

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

Only cool people share!

$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>
[/code]

 

PHP MySqli Check For No Results in Database was last modified: March 8th, 2019 by Maximus Mccullough
Summary
PHP MySqli Check For No Results in Database
Article Name
PHP MySqli Check For No Results in Database
Description
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.
Author
PHP Web Development

Leave a Reply

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