On executing the code below, an error message appears. Why is this?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\User\Desktop\Xampp\htdocs\cart.php on line 51
$total = 0;
echo '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo '<tr>';
echo '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
echo '<td>'.$row['title'].' by '.$author.'</td>';
echo '<td>£'.$price.'</td>';
echo '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
echo '<td>£'.($price * $qty).'</td>';
$total += $price * $qty;
echo '</tr>';
}
echo '</table>';
echo '<p>Grand total: £'.$total.'</p>';
echo writeShoppingCart();
echo '<a href="cart.php?action=add&id=1">Add to cart</a>';