Forum Moderators: coopster

Message Too Old, No Replies

Changing the name of a $ POST variable

want to change the variable name not the data!

         

delboy1978uk

1:55 pm on May 9, 2007 (gmt 0)

10+ Year Member



Hi can anyone help, here's the scenario:

A page of mine shows this type of thing;

Item-----------Stock------Required-----Picked
Beach Ball-------9-----------3--------text_box_1
Bucket-----------4-----------1--------text_box_2
Spade------------3-----------2--------text_box_3

submit_button

The text box is part of a foreach loop, it adds the number to the end.

Once you submit, on the next page, I think i need another foreach loop to display the numbers keyed in each text box.
ie:

echo $_POST['textbox1']; print '<br>';
echo $_POST['textbox2']; print '<br>';

etc, for every textbox there is. I also pass a hidden variable with the total number of textboxes.

Any geniuses out there can help?
Cheers in advance
Del :-)

delboy1978uk

2:49 pm on May 9, 2007 (gmt 0)

10+ Year Member



oh right, okay well that was easy....

for ($x = 1; $x <= $_POST['totallines']; $x++) {

print $_POST['orderdetailsid'.$x].'<br>';

} //end for loop

jatar_k

3:17 pm on May 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sometimes just by posting the answer becomes clear ;)

nice work

jatar_k

3:21 pm on May 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



how about this as an alternate

$count = 1;
while (isset($_POST[{'textbox' . $count}])) {
echo $_POST[{'textbox' . $count}],'<br>';
$count++;
}

I think I got that syntax right. It won't care about totallines, it will just keep going until the var isn't set

delboy1978uk

10:29 am on May 15, 2007 (gmt 0)

10+ Year Member



Hey! Nice one!
Will use that code from now on, one less variable to worry about :-)