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>
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!