How can the error "mysql_fetch_array() expects parameter 1 to be resource, boolean given" be resolved in PHP code?
The error "mysql_fetch_array() expects parameter 1 to be resource, boolean given" occurs when the query execution fails and returns a boolean (false) instead of a resource. To resolve this issue, you need to check the query execution result before trying to fetch data. You can use conditional statements to handle the case where the query fails and returns a boolean value.
$result = mysql_query($query);
if($result === false){
echo "Query execution failed";
} else {
while($row = mysql_fetch_array($result)){
// Process fetched data
}
}
Keywords
Related Questions
- What factors should be considered when determining the cost of advertising on a website, such as banner ads?
- How can PHP developers avoid errors when passing array values as parameters in functions?
- How can PHP developers efficiently manage and store images, including creating thumbnails and associating hashes with image data?