I'm trying to pass an array from one page to another using a form with action=post. however i can't retrieve the array on the 2nd page. I've tried $array=$_POST['array']. I've tried $array[]=$_POST['array[]']. and finally I tried $array[0]=$_POST['array[0]']. anyone know how to do this? thanks!
What's your HTML? You have to do it like this: <input type="text" name="foo[]" /> Code (markup): Note the square brackets.
I think you're best bet would be to split it out of the array and then put it back together on the other side, assuming it's a simple (one level) array. // Page one (stick it in a form): for ($round=0;$round<count($array);$round++){ echo "<input type=hidden name='array$round' value='$array[$round]'>"; } //Page two (getting variables) for ($round=0;$exists == 0;$round++){ if (isset($_POST["array$round"])){ $array[$round] = $_POST["array$round"]; } else{ $exists = 1; } Code (markup): That should do the trick, you might have fix one or two syntax issues as I just type that up without testing. An easier way, if you already have the data when the first page loads, instead of getting it on that page via user input (a form), would be to just use a session. //Page 1: session_start(); $_SESSION['array'] = $array; //Page 2: session_start(); $array = $_SESSION['array']; Code (markup): A more complete script that will actually run for that: //test.php <? $array[0] = "hi "; $array[1] = "there "; $array[2] = "mom!"; session_start(); $_SESSION['array'] = $array; ?> <a href=test2.php>Click!</a> //test2.php <? session_start(); $array = $_SESSION['array']; print_r($array); // prints out "hi there mom!" ?> Code (markup): You could use a form submit to go to test2.php, or a meta redirect, or anything you want. I just used a link to make it easier to make. Hope this helps! -Submerged
thanks for the ideas, but the array is based on user input. People can tick checkboxes next to various cell phones on my site to compare features. you can see it here: http://www.mobilealmanac.com/company/a_d_0-Samsung.html
expecting the HTML <input name="phones[]" type="checkbox" value="$phoneid"> in PHP $phones = $_POST['phones'] foreach( $phone as $p) { if( isset($p) && $p<>'') { ///// place your code here } }