Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

I'm trying to Integrate HTML Purifier http://htmlpurifier.org/ to filter my user submitted data and I was wondering how can I fix this problem as I get the following error:-

on line 22: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

line 22 is.

if (mysqli_num_rows($dbc) == 0) {


Here is the php code.

if (isset($_POST['submitted'])) { // Handle the form. require_once '../../htmlpurifier/library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', 'UTF-8'); // replace with your encoding $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype $purifier = new HTMLPurifier($config); $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT users.*, profile.* FROM users INNER JOIN contact_info ON contact_info.user_id = users.user_id WHERE users.user_id=3"); $about_me = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['about_me'])); $interests = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['interests'])); if (mysqli_num_rows($dbc) == 0) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"INSERT INTO profile (user_id, about_me, interests) VALUES ('$user_id', '$about_me', '$interests')"); } if ($dbc == TRUE) { $dbc = mysqli_query($mysqli,"UPDATE profile SET about_me = '$about_me', interests = '$interests' WHERE user_id = '$user_id'"); echo '<p class="changes-saved">Your changes have been saved!</p>'; } if (!$dbc) { // There was an error...do something about it here... print mysqli_error($mysqli); return; } }

asked Nov 29, 2020 in SQL by (6.1k points)
edited Nov 29, 2020 by Appu

I am trying to Integrate HTML Purifier to filter my user-submitted data but I am getting the following error.

on line 22: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

line 22:

if (mysqli_num_rows($dbc) == 0) {

Here is the php code:

if (isset($_POST['submitted'])) { // Handle the form. require_once '../../htmlpurifier/library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $config->set('Core.Encoding', 'UTF-8'); // replace with your encoding $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // replace with your doctype $purifier = new HTMLPurifier($config); $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"SELECT users.*, profile.* FROM users INNER JOIN contact_info ON contact_info.user_id = users.user_id WHERE users.user_id=3"); $about_me = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['about_me'])); $interests = mysqli_real_escape_string($mysqli, $purifier->purify($_POST['interests'])); if (mysqli_num_rows($dbc) == 0) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $dbc = mysqli_query($mysqli,"INSERT INTO profile (user_id, about_me, interests) VALUES ('$user_id', '$about_me', '$interests')"); } if ($dbc == TRUE) { $dbc = mysqli_query($mysqli,"UPDATE profile SET about_me = '$about_me', interests = '$interests' WHERE user_id = '$user_id'"); echo '<p class="changes-saved">Your changes have been saved!</p>'; } if (!$dbc) { // There was an error...do something about it here... print mysqli_error($mysqli); return; } }

1 Answer

How many parameters are expected in Mysqli_num_rows () function?

php - Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

What does the Mysqli_num_rows () function accomplish?

The mysqli_num_rows() function returns the number of rows in a result set.

What is Mysqli_num_rows?

The mysqli_num_rows() function is an inbuilt function in PHP which is used to return the number of rows present in the result set. It is generally used to check if data is present in the database or not. To use this function, it is mandatory to first set up the connection with the MySQL database.

What is mysqli_result?

mysqli_result::data_seek — Adjusts the result pointer to an arbitrary row in the result. mysqli_result::fetch_all — Fetch all result rows as an associative array, a numeric array, or both. mysqli_result::fetch_array — Fetch the next row of a result set as an associative, a numeric array, or both.