"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given" error while trying to create a php shopping cart [duplicate]

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

This is the code I have in my product.php, every time I click on a product from the home page it comes up with the warning below:

if ( isset( $_GET['ID'] ) ) {
    $product_id = $_GET['ID'];
    $query = "SELECT Name, Genre, Price, Year, Picture FROM Products";
    $result = mysql_query( $query );

    while ( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) {
        echo "<div><p>Name: $row[0]</p><p>Genre: $row[1]</p><p>Price: $row[2]</p><p>Year: $row[3]</p></div>";
    }
    echo "<div><a href=\"cart.php?action=add&product=$product_id\">add to basket</a></div>";
}

and I get the warning:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/cart/product.php on line 12


Solution 1:

Year is a mysql reserved word you have to escape it using backticks ``

$query = "SELECT Name, Genre, Price, `Year`, Picture FROM Products";

you must use some kind of mysql error checking like below one

$result = mysql_query($query) or trigger_error(mysql_error());