Forum Moderators: coopster

Message Too Old, No Replies

POST variable arrays

         

ramoneguru

4:44 am on Apr 29, 2005 (gmt 0)

10+ Year Member



I have a form that keeps track of the number of loops this thing makes and turns it to POST data (this is all contained in the test.php page):

$i = 0;

echo '<form name = "sometest" action = "test.php" method = "POST">';
whlie ($i < 5)
{
counter[] = 1234 + $i;
$i++;
}
echo '<input type = "submit" name = "test" value = "test">';
echo '</form>';

if (isset($_POST[test]))
{
//print the array "counter"
}

I tried using print_r($_POST[counter]) but no success...I was thinking maybe some hidden type of thing, but that's very sloppy. How do I print the "counter" array?
--Nick

ironik

4:55 am on Apr 29, 2005 (gmt 0)

10+ Year Member



Is that you actual code? If it is there's a couple of reasons why it won't work. While is spelt wrong and the counter value is not echo'd out to the page.

while ($i < 5)
{
$counter = 1234 + $i;
echo '<input type="text" name="counter[]" value="' . $counter . '" />'
$i++;
}

// then...
if (isset($_POST['counter']))
{
print_r($_POST['counter']);
}

Apologies if you had only re-typed it for the forum post. Was this what you had?

ramoneguru

7:26 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



I did retype it from the original but had this missing
echo '<input type="text" name="counter" value="' . $counter . '" />'

Well, live and learn I suppose. Thanks for the info.
--Nick