tjohnson_nb Posted February 18, 2009 Share Posted February 18, 2009 I often post arrays using html like this; <td><b>Select This Product</b><input type='checkbox' name='product[13]' value='550.92'></td> Then I use this code to assign local variable names to the posted variables in the $_POST global; foreach ($_POST as $key=>$value) { $$key=$value; } I recently upgraded a server and the code above no longer works if an element of $_POST is an array as above. I would normally expect to have an array $product after this ran but I get nothing. I even tried explicitly assigning $product=$_POST['product'] and it didn't work. The only way I can access the info is like this; foreach ($_POST['product'] as $key=>$value) { [some code] } Is this a result of upgrading php? Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/ Share on other sites More sharing options...
ILMV Posted February 18, 2009 Share Posted February 18, 2009 Well for a start, why are they two $ in front of $key? Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765181 Share on other sites More sharing options...
tjohnson_nb Posted February 18, 2009 Author Share Posted February 18, 2009 Well for a start, why are they two $ in front of $key? Well suppose you have; <td><b>Select This Product</b><input type='text' name='foo' value='bar'></td> Then this code will create the variable $foo="bar"; foreach ($_POST as $key=>$value) { $$key=$value; } Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765186 Share on other sites More sharing options...
GingerRobot Posted February 18, 2009 Share Posted February 18, 2009 Well for a start, why are they two $ in front of $key? That's called a variable variable. That is, the variable that you are using is itself variable. In this case, the OP is using it to extract all of the data from the $_POST array - indeed, the code is equivalent to extract($_POST); As for the original question - could we see some actual code? There's no reason why that shouldn't be working, so perhaps there's something else amiss. Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765188 Share on other sites More sharing options...
tjohnson_nb Posted February 18, 2009 Author Share Posted February 18, 2009 As for the original question - could we see some actual code? There's no reason why that shouldn't be working, so perhaps there's something else amiss. I did post the code That's all there is. I was thinking of trying extract() to see if that worked but the code works for regular variables but it stopped working for array variables. I don't think it is a php5 issue since it works on a linux server with php5 but this is on wampserver where it stopped working. Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765197 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2009 Share Posted February 18, 2009 At the top of your processing script, put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> This will dump the contents of the $_POST array to the screen. See what you're getting back. Ken Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765209 Share on other sites More sharing options...
ILMV Posted February 18, 2009 Share Posted February 18, 2009 Well for a start, why are they two $ in front of $key? That's called a variable variable. That is, the variable that you are using is itself variable. In this case, the OP is using it to extract all of the data from the $_POST array - indeed, the code is equivalent to extract($_POST); As for the original question - could we see some actual code? There's no reason why that shouldn't be working, so perhaps there's something else amiss. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765302 Share on other sites More sharing options...
sasa Posted February 18, 2009 Share Posted February 18, 2009 if you don't check any checkbox form doesn't post element 'product' Quote Link to comment https://forums.phpfreaks.com/topic/145742-posting-arrays/#findComment-765444 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.