I seem to get this error message when I run this
please can someone help?
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\unisite\products.php on line 11
I can't figure this out at all :(
<?php
if(isset($_GET['action']) && $_GET['action'] == "add"){
$id = intval($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
} else {
$sql2 = "SELECT * FROM products WHERE prod_id = [$id] ";
$query2 = mysql_query($sql2);
if(mysql_num_rows($query2) != 0){
$row2 = mysql_fetch_array($query2);
$_SESSION['cart'][$row2]['prod_id'] = array("quantity" =>1, "price" => $row2['price']);
} else {
$message = "This product id is invalid";
}
}
}
?>
<h2 class="message"> <?php if(isset($message)){echo $message;}?> </h2>
<h1>Products page</h1>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$sql = "SELECT * FROM products ORDER BY name ASC";
$query = mysql_query($sql)or die(mysql_error());
while($row = mysql_fetch_assoc($query)){
?>
<tr>
<td><?php echo $row['name']; ?> </td>
<td><?php echo $row['prod_description']; ?> </td>
<td>£<?php echo $row['prod_price']; ?> </td>
<td><a href="index.php?page=products&action=add&id=<?php echo $row['id_prod']; ?>">add to cart</a></td>
</tr>
<?php
/**
* @author James Bell
* @copyright 2010
*/
}
?>
</table>