Hi all. Im building a shopping cart using an online tutorial in youtube, but i have an error
<?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 id_products=$id";
$query2 = mysql_query($sql2);
if(mysql_num_rows($query2) != 0){
$row2 = mysql_fetch_array($query2);
$_SESSION['cart'][$row2['id_products']] = array("quantity" => 1, "price" => $row2['price']);
}else{
$message = "This product id is invalid";
}
}
}
?>
<h2 class="message"><?php if(isset($message)){echo $message;} ?></h2>
<h1>Product</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['description']; ?></td>
<td><?php echo "$" .$row['price']; ?></td>
<td><a href="index2.php?page=products&action=add&id<?php echo $row['id_products'];?>">Add to Cart</a></td>
</tr>
<?php
}
?>
</table>
<p> </p>
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in F:\root\xampplite\htdocs\shopping\product.php on line 13
On the comment section some user had this problem and he said to check if the session names are correct and to do a die message which I did but I think my session names seems fine and an error occured when I tried to put a die message.
Never the less the tutorial is the best I ever did for php.
I appreciate the help :).