I want to share a situation where I better know about mysqli_num_rows() function.
At the time of developing login functionality, this function is very useful.
When you create code or write a query for as like,

$query = mysqli_query($connection_variable, "SELECT username, password FROM user WHERE username = '$username' AND password = '$password' ");

On this code or query, we give attention to some things like,

  1. On WHERE clause condition all posted variable which is in “$” notation write within in Single Quote (‘ ‘).
  2. If you use “mysqli” always remember it takes 2 parameters,
    Ist: Connection variable
    IInd: Query or query variable

After this query you think your login functionality is working fine if you test you get the result like all works but if you use some redirection after the query is true then,

You test with the wrong credentials till the code redirects to that page because the query is running correctly.

So for this problem we use “mysqli_num_rows()” function, this function check after running the query, how many rows of data we get.

If query didn’t get any row then your code not redirected to the page and you login functionality working great..!

In code, you check like this

if(mysqli_num_rows($query)>0){}

//returns the number of rows


Was this article helpful?
YesNo

By Bikash

My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.

3 thoughts on “Facts You want to Know About Use Of Mysqli_num_rows() Function”

Leave a Reply

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