Save values in the variable

0

Save values in a variable coming from GET

Example:

$id = $_GET['id'];
$dados = array($id);

Doubt:

How do I save all IDs? Well, I'll use those IDs to identify which product was selected.

I created a shopping cart using SESSION, when I clicked on the product, it saves the data in the session, but when I click on the product, I am verifying that the value of the product is greater than the credit that the user has, is greater then it goes to page to finalize the purchase, otherwise it returns to the products page, but it will appear to the user the products that he selected, that is, I placed an icon of a VISA on top of the product. But to put this icon, I'm checking to see if the $ _SESSION ['product_id'] is equal to the id of the product

    
asked by anonymous 04.03.2014 / 22:09

2 answers

2
$_SESSION['var'] = array();

array_push($_SESSION['var'], '1'); // adiciona no array
array_push($_SESSION['var'], '2'); // adiciona no array
array_push($_SESSION['var'], '3'); // adiciona no array
array_push($_SESSION['var'], '4'); // adiciona no array

foreach($_SESSION['var'] as $key)
  echo $key.'<br>';

link

    
04.03.2014 / 22:20
0

I recommend that you always use (int) before $ _GET ['id']. As the id comes via url it is a string and this way with int we will make sure that you always come a whole number. Use this:

$ id = (int) $ _GET ['id'];

    
04.03.2014 / 22:38