Call to a member function fetch_row() on a non-object

hi guys,

in need of some help please, I keep getting this error (Call to a member function fetch_row() on a non-object) for the below query
could you please help me.

			$listid = clean($_POST['province']);
			$v1 = clean($_POST['v1']);
			$v2 = clean($_POST['v2']);
			$radio = clean($_POST['Radio']);
			
			 if ($radio == 1) {
				$sortme = "ASC";
			 } else {
				$sortme = "DESC";
			 }

			$mysql = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

		$totalEntries = $mysql->query("SELECT COUNT(*) FROM ". $table ." WHERE province ='$listid' AND admin_app='1' AND rent BETWEEN $v1 AND $v2 ORDER BY rent $sortme");
		$totalEntries = $totalEntries->fetch_row();  // line 54 - where the error occurs !!!
		$totalEntries = $totalEntries[0];
		
		
Fatal error: Call to a member function fetch_row() on a non-object in C:\\xampp\\htdocs\\varsity\\search-province.php on line 54

I assume your query is failing, causing the $totalEntries variable to be FALSE rather than being a mysqli_result object of.

Could you place the following directly underneath your query:


var_dump($totalEntries);
echo $mysqli->error;

What does the clean function do (how is it “cleaning” the user submitted data)?

hi

thanks for the reply, I did as you asked, and this is the result :

bool(false)

I tested all of the inputs ) POST values and found some to be of an incorrect format, so I changed it to the correct format, but now I get this when trying to loop through the
result and echo the data.

Fatal error: Call to a member function fetch_array() on a non-object in,

the error occurs on this code, first line :

while($row = $result->fetch_array(MYSQLI_ASSOC)) {


   //..... echo data ....


}

The fatal error call to a member function … on a non-object occurs when you attempt to use a variable as if it were an object (i.e. by invoking a method using the -> operator). Whenever you see this error, perform a var_dump() on the variable you’re assuming to be an object, and check its type. If the type is FALSE (as it is likely to be in this case), then it means your previous assignment to said variable failed. That’s where you want to check for the error.

If you still are unable to solve it, then post the erroneous snippet here for further help.