简体   繁体   中英

Post array into next page

I have a hidden input with array:

<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->name.'" />

How do I post the value of this array into the next page?

I tried this method: $a = $_POST['item_name']; but then it gave me the following error:

Array to string conversion in C:\\xampp\\htdocs\\BSSecureTech\\payment.php on line 6
Array

Then I tried $a = $_POST['item_name'][0]; . It works but then I wouldn't know how many values are in the array. How do I kind of loop the [0] to let it post all the values in the array?

At first i suggest you to change in your HTML like this if your file extension is .php

<input type="hidden" name="item_name[<?=$cart_items?>]" value="<?=$obj->name?>" />

On PHP end check your post array like print_r($_POST); . Then catch your desired value by array index like this

$values = $_POST;
$item = $_POST['item_name']['your index'];
echo $item;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM