jaxdevil Posted November 12, 2008 Share Posted November 12, 2008 Below is my full code on the page I am working on. Its a very small page with a single form input. ARRAY _POST variables are sent to it and the foreach is there to turn the posted variables into hidden form fields so I can post the data back to the original page along with the new data entered in the single form field. The problem is the page stops begining where the foreach starts, and I cannot figure out why. I ran it through PHPDesigner 2008 and it shows it as valid code. What is wrong on this script? Thanks in advance, SK <center> <form name="newscancodes" action="http://<?=$_SERVER['HTTP_HOST']?>/pages/new_scancodes.php" target="opener" method="post"> <? foreach ($_POST as $key => $value) { if ($is_array($value)) { foreach ($value as $subkey => $subvalue) { ?> <input type="hidden" name="<?php echo $subkey; ?>" value="<?php echo $subval; ?>"> <? } } else { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <? } } ?> <font style="font-size: 0.8em;" face="Tahoma"> <b>Type the custom scancode value below</b> <br> <small><i><font color="red">Alphnumeric characters ONLY!</font></i></small> </font> <br> <input type="text" name="custom_scancode"> <br> <br style="line-height:3px"> <input type="image" src="http://<?=$_SERVER['HTTP_HOST']?>/images/submit_button.gif" value="submit" onclick="self.close();"> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/132473-solved-foreach-is-breaking-my-php/ Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 <? if (is_array($_POST)) { foreach ($_POST as $key => $value) { if ($is_array($value)) { foreach ($value as $subkey => $subvalue) { ?> <input type="hidden" name="<?php echo $subkey; ?>" value="<?php echo $subval; ?>"> <? } } else { ?> <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>"> <? } } } Check to make sure that post is an array before looping through it. Also make sure that your display_errors is turned on because I bet that is why it is stopping. This is just a blind guess though without any error information. Quote Link to comment https://forums.phpfreaks.com/topic/132473-solved-foreach-is-breaking-my-php/#findComment-688747 Share on other sites More sharing options...
jaxdevil Posted November 12, 2008 Author Share Posted November 12, 2008 Yes I see what it is using error reporting, the is_array is set as a variable ( it says $is_array instead of is_array) Thanks for the tip! SK Quote Link to comment https://forums.phpfreaks.com/topic/132473-solved-foreach-is-breaking-my-php/#findComment-688760 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.