Re: Re: A form and an array

From: Date: Fri, 24 Jul 2009 04:33:03 +0000
Subject: Re: Re: A form and an array
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-295797@lists.php.net to get a copy of this message
> Jason Carson wrote: > >>> Jason Carson wrote: >>> >>>> Hello everyone, >>>> >>>> Lets say I have a file called form.php with the following form on it >>>> that >>>> redirects to index.php when submitted. I would like to take the values >>>> of >>>> the text fields in the form and put them into an array, then be able >>>> to >>>> display the values in that array on index.php Does anyone know how I >>>> would >>>> do that? >>>> >>>> Here is my form... >>>> >>>> <form action="index.php" method="post"> >>>> <table> >>>> <tr> >>>> <td>Option1</td> >>>> <td><input type="text" name="option[]" >>>> /></td> >>>> </tr> >>>> <tr> >>>> <td>Option2</td> >>>> <td><input type="text" name="option[]" >>>> /></td> >>>> </tr> >>>> <tr> >>>> <td></td> >>>> <td><input value=submit" name="submit" >>>> type="submit" /></td> >>>> </tr> >>>> </table> >>>> </table></form> >>> >>> You'll find they are already in an array which you can access as >>> $_POST['option'] - from there foreach() should be the next step. >>> >>> >>> Cheers >>> -- >>> David Robley >>> >>> Polls show that 9 out of 6 schizophrenics agree. >>> Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> I am new to programming. How would I use foreach()to display the entries >> in the array? > > You could read TFM which has an example - > http://php.net/manual/en/control-structures.foreach.php > > > Cheers > -- > David Robley > > Why are you wasting time reading taglines? > Today is Setting Orange, the 59th day of Confusion in the YOLD 3175. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > What I currently have is... foreach ($_POST['option'] as $value) { echo "Value: $value<br />\n"; } ...but that doesn't work. TFM didn't help me :-(

« previous php.general (#295797) next »