mysql - PHP Database query result error
663
Well, basically here is the error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in
Here is my code:
function user_banned ($con, $username) {
$result = mysqli_query($con, "SELECT `banned` FROM `users` WHERE `username` = '$username'");
return(mysqli_num_rows($con) == 1) ? true : false;
}
I am not too sure what is causing this, I have seen several questions about this issue, however none of them have assisted my in finding a way to fix this issue.
Answer
Solution:
You should add an extra column to your
where
clause:AND banned='yes'
as an example.Plus, you're using the wrong variable in
you need to use the query variable and not the connection
which explains the initial error:
Answer
Solution:
http://php.net/manual/en/mysqli-result.num-rows.php
You are passing the conn it should be as
Answer
Solution:
Try this:
Answer
Solution:
Did you try with $result instead of $con for mysqli_num_rows ?
You should also check if your connection to your database is good.
Answer
Solution:
You dont want to pass in the connection, you need to pass in the result of the query.
needs to have the return be:
Your error says exactly that. It is looking for a
mysqli_result
and not anobject
Your actual error is based around things returning true because you are using the wrong query. Ill follow your example on the returned select and say:
SELECT 'banned' from 'users' WHERE 'username' = '$username' AND 'banned' IS TRUE
this is assuming banned is a bool of course, and not a string, bit, int, etc.