Hi Everybody,
I am PHP newbie and i am working on a shopping cart. I am trying to work on it myself in order to grasp very well the whole concept and expand it to the way i want. For days i have been trying to sort it out, but God i am hitting a wall, i am posting the whole code to you, so that you can see the logic i am trying to create and help me better.
These are the erros i am getting : Warning: Illegal string offset ‘code’ in C on line 54 and this one W
arning: Illegal string offset ‘qty’ in C on line 56.
Here are my code:
index.php
[php]<?php
session_start();
include_once(‘includes/connect.php’);
try {
$sql =“SELECT * FROM products LIMIT 3”;
$result = $pdo->query($sql);
$items = $result->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo “Problem with code”.$e->getMessage();
}
if (!isset($_SESSION[‘cart’]) || count($_SESSION[‘cart’]) < 1) {
$_SESSION['cart'] = array();
}
if (isset($_POST[‘action’]) && $_POST[‘action’]==‘Add to cart’) {
$item_name[‘code’] = $_POST[‘product_code’];
$item_name[‘qty’]= $_POST[‘prod_qty’];
$_SESSION[‘cart’][] = $item_name;
header(‘Location: .’);
exit();
}
if (isset($_GET[‘cart’])) {
$cart = array();
foreach ($_SESSION[‘cart’] as $prodcode) {
$cart[‘code’] = $prodcode[‘code’];
$cart[‘qty’] = $prodcode[‘qty’];
}
include_once(‘cart.html.php’);
exit();
}
include_once(‘catalog.html.php’);
?>
[/php]
cart.html.php
[php]
View cart<h4>Your shopping cart</h4>
<?php if (count($cart)>0):?>
<?php echo $Item['code'];?> | <?php echo $Item['qty'];?> |