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
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 />";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.