andreea115 — 2012-09-09T22:12:20-04:00 — #1
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
//the global connection.
$qb = "UPDATE users
user_id = '$id ' ";
$rb = mysqli_query ($dbc, $qb); // Run the query.
$returnrows = mysqli_num_rows( $rb );
if ( $returnrows == 1)
$account = deactivate_account(18);
thank you for your kind attention.
spacephoenix — 2012-09-09T23:21:16-04:00 — #2
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?
yeyongde — 2012-09-09T23:51:05-04:00 — #3
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.
chris_upjohn — 2012-09-10T08:10:23-04:00 — #4
Easiest and quickest way to debug the issue is to use the following:
$rb = mysqli_query ($dbc, $qb) or die(mysqli_error($dbc));
guido2004 — 2012-09-10T08:29:15-04:00 — #5
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.
starlion — 2012-09-10T09:04:38-04:00 — #6
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.
andreea115 — 2012-09-15T03:18:54-04:00 — #7
thank you to everyone for your kind help and assistance with this query. YOu have all clarified the issues for me.