Facts You want to Know About Use Of Mysqli_num_rows() Function

By | June 3, 2020

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 wrong credentials till the code redirects to that page because of 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

}


Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

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

  1. Pingback: Simple PHP MySQL CRUD Operation - phpcoder.tech CRUD PHP MySQL

Leave a Reply

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