Jump to content

Recommended Posts

ok, im trying to retrieve some variables which were created using a form. Each variable was initialized like so:
[code]

<input name="page_name<? $i ?>" type="text" class="style183" size="40">

[/code]

then if the form is submitted i'm trying to access the variables like this:
[code]

for ($i = 1; $i <= (($_SESSION['no_of_pages'])+2); $i++)
{
    $page_name[$i] = $_POST['page_name[$i]'];
    echo "".$page_name[$i];
}

[/code]

Its the $_POST['page_name[$i]']; bit that i think may be wrong. 

Can anyone shed any light on this?

Cheers!
Link to comment
https://forums.phpfreaks.com/topic/26047-_post-array-variables/
Share on other sites

Not sure I really get it but

I think it should be:

[code]for ($i = 0; $i <= (($_SESSION['no_of_pages'])+2); $i++)
{
    $page_name = $_POST['page_name[$i]'];
    echo "".$page_name;
}
[/code]

why use $i on page_name?
Arrays are zero based. Start at 0.

Hope this helps you. If not, sorry that I might of misunderstood your code.
Link to comment
https://forums.phpfreaks.com/topic/26047-_post-array-variables/#findComment-119104
Share on other sites

Going back to the OP's original code. If the input line is
[code]
<input name="page_name<? $i ?>" type="text" class="style183" size="40">
[/code]
as was stated, then none of the solutions will work since the above statement will not really work as intended. The correct line would be either
[code]
<input name="page_name<?php echo $i ?>" type="text" class="style183" size="40">
[/code]
or
[code]
<input name="page_name[<?php echo $i ?>]" type="text" class="style183" size="40">
[/code]

I personally prefer the second form, since then the incoming values can be referenced as values in the $_POST['page_name'] array:
[code]<?php
for ($i=0;$i<count($_POST['page_name']);$i++) {
//
//  do your code
//
}
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/26047-_post-array-variables/#findComment-119121
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.