How to send 2 arrays / parameters via url?

0

I'm trying to send two parameters of the shopping cart through url, then the client to confirm, but I can only get an array on the other page and I do not know how to get two.

I want to send the quantity of products and the product_id to the page on another page, where the user will confirm and then insert into database >.

On the cart page

<?php
**// array para guardar todos os valores que estão no carrinho
$emparray[] = $product['id_produto'];
$quant[] = $product['quantidade'];
...

// transformar a array numa associação de parâmetros para a url
$query = http_build_query($emparray);
testar = http_build_query($quant);

$cart_box .= '<div class="cart-products-total">Total : '.$total.' € <u><a href="index.php?page=confirmar_encomenda&'.$query.'&'.$testar.'"  title="Verifica o carrinho e faz checkout">Concluir</a></u></div>';

?>

On the other page, that's how I get the values. In order to send in the form confirmation.

<?php
$teste=$_GET;
echo $teste;

foreach($teste as $value){
   echo' <input type='text" name="result[]" value="'. $value.'">';
}
?>

But this way it just shows the last array and I've already tried N forms to get the two separated but I could not.

    
asked by anonymous 18.03.2017 / 22:58

1 answer

2

Two things:

  • Avoid passing this type of purchase data to GET , use the POST method. In addition to being more secure, you have limit on the number of characters you can pass through GET of 2083 characters. It looks like a lot, but if your customer is buying 100 different products you may well go over that limit.

  • When you define arrays that are going to go through http_build_query you are passing the value directly, so the resulting arrays must be arrays with numbered indexes instead of associative, so GET must be overwriting the arrays. parameters that you are passing to it, ie: the result in the URL must be more than one parameter with the same key: ?page=confirmar_encomenda&0=1344&0=2 . Instead of using two arrays, why not pass the array products that contain all the information?

  • $query = http_build_query($product);

        
    19.03.2017 / 02:18