Hi,
I am pretty new to PHP and I am trying to create a shopping cart.
I keep on getting the below error when trying to show the shopping list.
Any guidance that can be provided will be very much appreciated
Fatal error: Call to a member function query() on a non-object in
C:\wamp\www\draft\basket.php on line 36
mysql_connect.php
basket.php
Rum Basket
Rum on Offer
query($sql);
$output[]= '';
while ($row = $result->fetch()) {
$output[] = ''.$row['name'].': £'.$row['price'].'Add to Cart';
}
$output[] = '';
echo join ('', $output);
?>
cart.php
$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
Rum Basket
Please Check Quantities...
Back to Rum List
functions.php
There is no alcohol in your Rum Basket';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return 'There are'.count($items).' item'.$s.' in your
rum basket';
}
}
function showCart() {
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '';
$output[] = '';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM spirits WHERE id = '.$id;
$result = $con->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '';
$output[] = 'Remove';
$output[] = ''.$name.'';
$output[] = '£'.$price.'';
$output[] = '';
$output[] = '£'.($price * $qty).'';
$total += $price * $qty;
$output[] = '';
}
$output[] = '';
$output[] = 'Grand total: £'.$total.'';
$output[] = 'Update cart';
$output[] = '';
} else {
$output[] = 'You shopping cart is empty.';
}
return join('',$output);
}
?>
Many Thanks
Vee