Home > Database > Mysql Tutorial > Why Does My PHP Code Throw \'mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given\'?

Why Does My PHP Code Throw \'mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given\'?

Linda Hamilton
Release: 2024-11-23 01:26:33
Original
358 people have browsed it

Why Does My PHP Code Throw

"mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given" Error: Troubleshooting in PHP

The "mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given" error in PHP arises when the first parameter passed to mysqli_fetch_array() is not a valid result set from a successful MySQL query.

Problem:

In the provided code snippet, the query "SELECT * FROM users WHERE fb_id = " . $fb_id . " LIMIT 0, 30 " is not executing successfully. As a result, mysqli_query() returns false, which is then passed as the first parameter to mysqli_fetch_array(). This causes the error.

Solution:

To fix the error, you need to ensure that the MySQL query is valid and returns a valid result set. Add the following code after mysqli_query() to check for errors and display them:

if (!$check1_res) {
    trigger_error(mysqli_error($con), E_USER_ERROR);
}
Copy after login

This will output the error message if the query fails, helping you identify the issue.

Possible Causes:

  • Database connection issues: Ensure that the database connection ($con) is valid.
  • Syntax errors in the query: Check the query for any typos or incorrect syntax.
  • Permission denied: Verify that the user has the necessary permissions to perform the query.
  • Invalid table or field names: Make sure the table users and the field fb_id exist in the database.

Additional Information:

  • For more information on mysqli_error(): https://www.php.net/manual/en/mysqli.error.php
  • Refer to the MySQL documentation for guidelines on writing correct queries: https://dev.mysql.com/doc/

The above is the detailed content of Why Does My PHP Code Throw \'mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given\'?. 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