Pod adresem http://www.nettuts.com/demos/01_ShoppingCart/index.html jest demo jak ten skrypt działa.
Na moim hostingu i na localhost wyskakuje błąd: Warning: Invalid argument supplied for foreach() in line 13
To jest ten kod, miejsce z niedziałającą funkcja jest zakomentowane:
CODE
<?php
include('shopping_cart.class.php');
session_start();
$Cart = new Shopping_Cart('shopping_cart');
if ( !empty($_GET['order_code']) && !empty($_GET['quantity']) ) {
$quantity = $Cart->getItemQuantity($_GET['order_code'])+$_GET['quantity'];
$Cart->setItemQuantity($_GET['order_code'], $quantity);
}
//*****************************************************************************
//to jest ten foreach poniżej, który nie działa
if ( !empty($_GET['quantity']) ) {
foreach ( $_GET['quantity'] as $order_code=>$quantity ) {
$Cart->setItemQuantity($order_code, $quantity);
}
}
if ( !empty($_GET['remove']) ) {
foreach ( $_GET['remove'] as $order_code ) {
$Cart->setItemQuantity($order_code, 0);
}
}
$Cart->save();
header('Location: cart.php');
?>
include('shopping_cart.class.php');
session_start();
$Cart = new Shopping_Cart('shopping_cart');
if ( !empty($_GET['order_code']) && !empty($_GET['quantity']) ) {
$quantity = $Cart->getItemQuantity($_GET['order_code'])+$_GET['quantity'];
$Cart->setItemQuantity($_GET['order_code'], $quantity);
}
//*****************************************************************************
//to jest ten foreach poniżej, który nie działa
if ( !empty($_GET['quantity']) ) {
foreach ( $_GET['quantity'] as $order_code=>$quantity ) {
$Cart->setItemQuantity($order_code, $quantity);
}
}
if ( !empty($_GET['remove']) ) {
foreach ( $_GET['remove'] as $order_code ) {
$Cart->setItemQuantity($order_code, 0);
}
}
$Cart->save();
header('Location: cart.php');
?>
Na prezentowanym wczesniej linku powyżej ten skrypt działa i dobrze się ma. Na dwóch serwerach z których korzystam to nie chce chodzić. Dlaczego?