Ik zit met een probleem.
Als ik een nieuw product toevoeg en heb er al een in gaat het fout. Wat klopt er niet aan deze code? De producten worden als volgt in de sessie gezet: 4454,1|5757,2 PRODUCTNUMMER,AANTAL
<?php
// add.php
session_start();
echo $_SESSION['cart'];
if($_GET['art'])
{
if(empty($_SESSION['cart']))
{
$_SESSION['cart'] = $_GET['art'].",1";
}
else
{
$cart = explode("|",$_SESSION['cart']);
$products = explode(",",$cart);
echo $cart."-".$products;
// Winkelwagen inhoud tellen
$count = count($cart);
// En controleren of het product al in de winkelwagen zit
$add = TRUE; // var om later te kijken of we moeten toevoegen
print_f($cart);
foreach print_f($cart);
{
$i++;
if ($i == 1) {
$_SESSION['cart'] = $products[0].",11";
} else {
$_SESSION['cart'] = $_GET['art'].",13|".$products[0].",".$products[1];
}
}
if ($add) { // Als we dus wel moeten toevoegen
$_SESSION['cart'] = $products[0].",1|".$_GET['art'].",12";
}
}
}
?>
1.401 views