Home > Database > Mysql Tutorial > Why Does \'mysql_fetch_array() expects parameter 1 to be resource, boolean given\' Error Occur?

Why Does \'mysql_fetch_array() expects parameter 1 to be resource, boolean given\' Error Occur?

Mary-Kate Olsen
Release: 2024-11-03 09:09:30
Original
948 people have browsed it

Why Does

mysql_fetch_array() expects parameter 1 to be resource problem

The error "mysql_fetch_array() expects parameter 1 to be resource, boolean given" indicates that the first parameter passed to the mysql_fetch_array() function is not a valid MySQL resource. This error can occur when you try to fetch data from a database after an unsuccessful query execution.

In your provided code snippet, you are trying to fetch data from the student table using the mysql_fetch_array() function. However, you are not checking the result of the mysql_query() function, which checks if the query was executed successfully. If the query fails, it will return false, which is a Boolean value.

To fix this issue, add the following check after the mysql_query() call:

<code class="php">if (!$result) { // add this check.
    die('Invalid query: ' . mysql_error());
}</code>
Copy after login

If the query is unsuccessful, this check will display an error message and terminate the execution of the script. Otherwise, you can proceed to fetch data from the result variable using the mysql_fetch_array() function.

The above is the detailed content of Why Does \'mysql_fetch_array() expects parameter 1 to be resource, boolean given\' Error Occur?. 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