Jump to content

Confused


thomashw

Recommended Posts

Can anyone help me get this working? I'm doing a "tutorial" to create a shopping cart. This page is to actually display the contents of the cart, but I've not seen PHP coded like this before, and it's giving me an error saying "Fatal error: Call to a member function query() on a non-object."

 

<?
$id = intval($_GET['product_id']);
$total = 0;
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM feature_product WHERE feature_product_id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
$output[] = '<td>'.$title.' by '.$author.'</td>';
$output[] = '<td>£'.$price.'</td>';
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>£'.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: £'.$total.'</p>';
?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/85381-confused/
Share on other sites

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.