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,
- On WHERE clause condition all posted variable which is in “$” notation write within in Single Quote (‘ ‘).
- 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
//returns the number of rows