Home > Backend Development > PHP Tutorial > Why Does `mysqli_num_rows()` Return a Boolean Instead of a `mysqli_result` Object?

Why Does `mysqli_num_rows()` Return a Boolean Instead of a `mysqli_result` Object?

Patricia Arquette
Release: 2024-11-29 03:14:12
Original
543 people have browsed it

Why Does `mysqli_num_rows()` Return a Boolean Instead of a `mysqli_result` Object?

PHP & MySQL: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

Problem

When integrating HTML Purifier into a PHP script, an error occurs in line 22: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given. The error is triggered when attempting to check the number of rows returned by a MySQL query.

Solution

The error is caused by an incorrect SQL query in line 22, which is:

$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");
Copy after login

The error is: "You do not join with profile anywhere." This means that the query is trying to join the users and profile tables on the user_id column, but the profile table is not included in the FROM clause.

To fix the issue, the profile table needs to be included in the FROM clause, like so:

$dbc = mysqli_query($mysqli,"SELECT users.*, profile.*
                                 FROM users 
                                 INNER JOIN profile ON contact_info.user_id = users.user_id 
                                 WHERE users.user_id=3");
Copy after login

With this change, the query will correctly join the users and profile tables and return the desired results.

The above is the detailed content of Why Does `mysqli_num_rows()` Return a Boolean Instead of a `mysqli_result` Object?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template