Jump to content

Shopping Cart - Not Working


Dysan

Recommended Posts

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>';

Link to comment
https://forums.phpfreaks.com/topic/77673-shopping-cart-not-working/
Share on other sites

Can data in the database be displayed without using a while loop. Obviously only one record will get displayed.

 

mysql_select_db("db", $con);

$result = mysql_query("SELECT * FROM details");

while($row = mysql_fetch_array($result))
{
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.