Jump to content

[SOLVED] foreach is breaking my php?!?


jaxdevil

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/132473-solved-foreach-is-breaking-my-php/
Share on other sites

<?
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.