0

I'm creating an $item array that I'd like to push to $_SESSION['cart']. After constructing my item array, I am trying:

$_SESSION['cart'][] = $item[$item_id];

Referencing: Can I use array_push on a SESSION array in php?

However, my cart session variable keeps getting overwritten, rather than added to. Any other suggestions?

As requested from Mark:

First time being run:

Notice: Undefined variable: _SESSION in C:\inetpub\wwwroot\domain\store\cart.php on line 5
NULL array(3) { ["title"]=> string(37) "PA State and Federal Laminated Poster" ["price"]=> string(5) "55.95" ["qty"]=> string(1) "3" }

Second time:

Notice: Undefined variable: _SESSION in C:\inetpub\wwwroot\domain\store\cart.php on line 5
NULL array(3) { ["title"]=> string(53) "PA State and Federal Laminated Poster SPANISH Edition" ["price"]=> string(5) "55.95" ["qty"]=> string(1) "1" }
Community
  • 1
  • 1
etm124
  • 2,100
  • 4
  • 41
  • 77

1 Answers1

1

You have to call session_start() before you reference $_SESSION. The output you posted indicates you don't do that.

Notice: Undefined variable: _SESSION in C:\inetpub\wwwroot\domain\store\cart.php on line 5

Matt
  • 6,993
  • 4
  • 29
  • 50