How to pass array values ​​in query string in php

I need your help.

How to pass array values ​​in a query string ...

<?php 
                foreach ( $Cart->getItems() as $order_code=>$quantity ) :
                $pname[]= $Cart->getItemName($order_code);
                $item[]= $Cart->getItemPrice($order_code);
                $qty[]=$quantity;
                endforeach;
                ?>
                <form action='expresscheckout.php?amt=<?php echo $total_price; ?>&item_name=<?php echo $pname; ?>&unit=<?php echo $item; ?>&quan=<?php echo $qty; ?>' METHOD='POST'>
<input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' border='0' align='top' alt='Check out with PayPal'/>
</form>

This is my sample code., For the above code example, do I need to pass a query string at my action url, which is expresscheckout.php expression? amt = 100. etc., fall under $ pname [], $ clause [], $ pcs [].

Waiting for output in expresscheckout.php

expresscheckout.php? pname = product1, product2 & item = item1, item2 & qty = 1,2,3 .... like this ....

Thanks in Advance ....

0
source share
3 answers

, PHP implode, , . $item:

$item = array('item1', 'item2');
echo implode(',', $item);

:

item1,item2

, - , , :

echo 'pname='.implode(',', $pname).
     '&item='.implode(',', $item).
     '&qty='.implode(',', $qty);
0

, []. ,

<form method="post" action="path to script">
<input type="checkbox" id="colors[]" value="red" /> Red
<input type="checkbox" id="colors[]" value="blue" /> Blue
<input type="checkbox" id="colors[]" value="green" /> Green
<input type="checkbox" id="colors[]" value="yellow" /> Yellow
</form>

PHP

$colors=$_POST['colors']; //takes the data from a post operation...
$query=INSERT INTO colors VALUES('$colors');
+10

php

PHP .

PHP , unserialize().

ref: -

http://php.net/manual/en/function.serialize.php

http://www.php.net/manual/en/function.unserialize.php

$my_array= (array('val1', 'val2','val3');

server.php?query_string=serialize($my_array)

$query_string= unserialize($_REQUEST['query_string']);

,

-1

Source: https://habr.com/ru/post/1606294/


All Articles