I cannot get mysqli_num_rows to work

hi everyone.

i am trying to use mysqli_num_rows within a php function ( i am using the function to determine whether a user was able to deactivate their account). ult.

i cannot however seem to get it to work. the result always returns the following error message:


warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\babysitter-agency.com\cms\db_fns.php on line 51

i enclose my code below



	
function  deactivate_account($id)

{	
	
	//the global connection.
	global $dbc;
	
		$qb = "UPDATE users
		SET
		live= '1'			
		
		WHERE
		 user_id = '$id ' ";
		
		$rb = mysqli_query ($dbc, $qb); // Run the query.

                 $returnrows  =     mysqli_num_rows( $rb );

                 if (   $returnrows == 1)
                 	 {
                 	  return $returnrows;
                 	 }
                 else
                 return '';

}
  $account     =    deactivate_account(18);


echo "$account";



thank you for your kind attention.

warm regards

Andreea

That error normally means that the query that was last executed has failed. Echo your query and try it direct against the database. Are the field and table names used in the query correct?

you do not pass variable $dbc to the scope within the function deactivate_account. i sugget that you need to do like this

function deactivate_account($id, $dbc) //this enables to pass the database connection object into the function scope in order to use this connection in $rb = mysqli_query($dbc, $qb);
warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\babysitter-agency.com\cms\db_fns.php on line 51:::this warning means your conncetion to database is not found so Boolean value 0 returned as a result of no conncetion been passed to the function.

Easiest and quickest way to debug the issue is to use the following:

$rb = mysqli_query ($dbc, $qb) or die(mysqli_error($dbc));

UPDATE queries don’t return a result set, they return TRUE if the query ended well.
Use affected_rows to get the number of affected rows for an UPDATE query.

Also worth mentioning that TRUE does not mean ‘changed a row’, it simply means ‘did not throw error’. You can get a TRUE result and have modified 0 rows, which is why checking the affected_rows is important.

thank you to everyone for your kind help and assistance with this query. YOu have all clarified the issues for me.