Store values in the variable

Asked

Viewed 823 times

0

Store values in a variable by GET

Example:

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

Doubt:

How to save all Ids? Because I will use these Ids to identify which product was selected.

I created a shopping cart using SESSION, when clicking on the product, it records in Sesssion its data, but when clicking on the product, I am checking if the value of the product is greater than the credit that the user has, if it is bigger then it goes to page to finalize the purchase, otherwise, it goes back to the product page, but will appear to the user the products he has selected, ie, I put a VISA icon on top of the product. But to put this icon, I’m checking to see if the $_SESSION['idProduct'] is equal to the product id

  • 1

    Save in session and then rescue.

  • John, can you give an example?

  • $id = $_GET['id']; $id2 = $_GET['id2']; $id3 = $_GET['id3']; $id4 = $_GET['id4']; $data = new Array($id, $id2, $id3, $id4) Your code is similar to this one?

  • 1

    @Samirbraga I created a shopping cart using SESSION, by clicking on the product, it records its data to Session, but by clicking on the product, I’m checking to see if the value of the product is greater than the credit the user has, if it is bigger then it goes to page to finalize the purchase, otherwise it goes back to the products page, but will appear to the user the products he selected, IE, I put a VISA icon on top of the product. But to put this icon, I’m checking to see if the $_SESSION['idProduct'] is equal to the product id.

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>';

http://br.php.net/array_push

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 let’s make sure that you always come up with an integer number. Use like this:

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

Browser other questions tagged

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