Jump to content

[SOLVED] Strange session problem


c_shelswell

Recommended Posts

Got this strange problem in a shopping cart i'm building. This is working absolutely fine on my dev pc (php5) but not working online also php5.

 

my code is

$new = $_GET['media_id'];
if ($new)
{
    if (!isset($_SESSION['cart']))
    {
        $_SESSION['cart'] = array();
        $_SESSION['items'] = 0;
        $_SESSION['total_price'] = '0.00';
    }
    if (isset($_SESSION['cart'][$new]))
    {
        $_SESSION['cart'][$new] += 1;

    }
    else
        $_SESSION['cart'][$new] = 1;
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
}

which should basically add a new item to the cart. On ie6 the it doesn't seem to add anything at all on firefox it works the first time you add an item then the second time you get this error:

 

Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /home/chriss/public_html/cart_add.php on line 16

 

referring to this line "$_SESSION['cart'][$new] += 1;"

 

Like i say the whole cart is working fine on my box just not online what's even stranger is how ie6 and firefox would react differently to a php script

 

any ideas?

 

Cheers

 

meant to say if i do a print_r session online the 'cart' variable is empty and not even set as an array

Link to comment
https://forums.phpfreaks.com/topic/39047-solved-strange-session-problem/
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.