Jump to content

Simple Loop Syntax Problem - Please Help!


stuartbrown20

Recommended Posts

Hey guys, i have this loop which is causing me problems and i'm not sure why. I assume it's a syntax problem but i just can't seem to identify the issue. Can anyone help me pleaaase!!!!

[code]<?php
for($i = 0; $i < 20); $i++) {
?>
<input type="hidden" name="suburb<?php echo $i; ?>" value="<?php echo $_POST['suburb$i']; ?>" />
<?php
}
?>[/code]
Link to comment
Share on other sites

You have a right parenthesis after the 20, and you're using single quotes in the $_POST array key. Try:

[code]
for ($i = 0; $i < 20; $i++) {
    echo '<input type="hidden" name="suburb', $i, '" value="', $_POST["suburb$i"], '" />';

}
[/code]

While testing/debugging this, make sure you have error_reporting(E_ALL); at the top of your script so you can see all of PHP's errors/warnings/notices. Also, have display_errors on in the php.ini file. Otherwise, set it using ini_set('display_errors', '1'); at the top of your script too.

Link to comment
Share on other sites

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.