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

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

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

}


Was this article helpful?
YesNo

Advertisement

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 *