lazerweb Posted March 12, 2011 Share Posted March 12, 2011 Hi, I do a form post from one page1.php to page2.php This is my php code on page2.php : <?php if ($_POST) { echo '<pre>'; echo htmlspecialchars(print_r($_POST, true)); echo '</pre>'; } ?> It gives me this result: Array ( [1] => Array ( [item1] => Nails sml [Price1] => 10 [Qty1] => 42 [LineTotal1] => €420.00 ) [2] => Array ( [item2] => Nails lrg [Price2] => 12 [Qty2] => 35 [LineTotal2] => €420.00 ) [3] => Array ( [item3] => Nails brown [Price3] => 5 [Qty3] => 14 [LineTotal3] => €70.00 ) [4] => Array ( [item4] => Black Nails [Price4] => 10 [Qty4] => 15 [LineTotal4] => €150.00 ) [5] => Array ( [item5] => Rusted Nails [Price5] => 10 [Qty5] => 15 [LineTotal5] => €150.00 ) [Total4] => €1210.00 [Client_Details] => Array ( [Company] => Lazerweb [Contact] => theo [Tel] => 0114567890 => theo@tm4y.co.za [Delivery_Address] => 822 Witwatersrand Ave,Strubensvalley,Gauteng,1735 Ok, so here is my problem: I could simply do the following : <?php echo $_POST['1']['Item1']; ?> but the problem is that the input boxes from page1.php where this post comes from : [1] => Array ( [item1] => Nails sml [Price1] => 10 [Qty1] => 42 [LineTotal1] => €420.00 etc. etc. are created from a csv file (I loop through every row), so I do not know how many rows there will be. It can be 1 or 100. Therefore arrays 1 to 5 can be arrays 1 to 100. The only arrays that are constant and will not change is [Total4] and [Client_Details] I therefore cannot hard code these values, how would I go about doing this? Thx Theo Quote Link to comment Share on other sites More sharing options...
flolam Posted March 12, 2011 Share Posted March 12, 2011 remove the appended number from the field names (so for example "Item1", "Item2" etc. becomes simply "Item") and then $total4 = $_Post["Total4"]; $client_details = $_Post["Client_Details"]; unset($_Post["Client_Details"]); unset($_Post["Total4"]); foreach ($_Post as $inputgroup) { echo $inputgroup["Item"]; echo $inputgroup["Price"]; //... } Quote Link to comment Share on other sites More sharing options...
lazerweb Posted March 13, 2011 Author Share Posted March 13, 2011 Hi, thank you for your help, however I get the following message: Warning: Invalid argument supplied for foreach() in W:\www\checkout.php on line 76 This is the line: foreach ($_Post as $inputgroup) { I suppose it should be $_POST and not $_Post ? Theo Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2011 Share Posted March 13, 2011 Precisely. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.