Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.