How to increment a value to a session?

Asked

Viewed 328 times

0

I’m looking to add a value to a GET session. I’m doing it this way but it doesn’t work.

function addCart($product){         
  $cart['cart'][$product] = 0;
  $_SESSION[] = $cart;
}
  • Doesn’t work means what? that the new item goes with a numerical input?

  • 1

    the variable $cart is not set and causes error, you need to check if it exists, and create conditions for whether or not it exists

  • It didn’t work. What I wanted was to store the ids of a product in the session, go incrementing them every get.

  • Ryan, I suggest you also give a name for your $_SESSION[]

1 answer

1

  • despite the need to log in, call the function session_start() inside another function does not seem a good idea, if the function is called more than once it will cause error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.