Home > Database > Mysql Tutorial > Why Does `mysqli_num_rows()` Return 'boolean given' After Using HTML Purifier and `mysqli_query()`?

Why Does `mysqli_num_rows()` Return 'boolean given' After Using HTML Purifier and `mysqli_query()`?

Linda Hamilton
Release: 2024-12-26 20:45:10
Original
489 people have browsed it

Why Does `mysqli_num_rows()` Return

mysqli_num_rows() Expects Parameter 1 to be mysqli_Result, Boolean Given in PHP & MySQL

Error Message

When using HTML Purifier to filter user input and executing a query using mysqli_query(), you may encounter the error:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Copy after login

This error occurs when mysqli_num_rows() is called with a boolean value instead of an mysqli_result object.

Solution

The root cause of the error is an issue in the SQL query. In the given code, the query:

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

contains an error: there is no JOIN with the profile table anywhere in the query. To fix this, you need to include the correct JOIN statement in the query.

The corrected query:

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

The above is the detailed content of Why Does `mysqli_num_rows()` Return 'boolean given' After Using HTML Purifier and `mysqli_query()`?. 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