Re: problem with foreach
| From: | Stut | Date: | Mon, 22 Oct 2007 19:06:49 +0000 |
| Subject: | Re: problem with foreach | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263515@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
On Mon, 2007-10-22 at 18:07 +0100, Stut wrote:Good point. Has the OP checked any of the boxes? If not then that array will not exist in $_POST. -Stut -- http://stut.net/Adam Williams wrote:He's still going to get an invalid argument warning though since PHP will automatically convert the unquoted key to a string and then look up the value. The problem is that the value doesn't exist or is not an array as expected.I have an html page with checkboxes: <form action=mailform2.php method=POST> <input type=checkbox name=option[] value="Modern Mississippi">Modern Mississippi<br> <input type=checkbox name=option[] value="Civil Rights">Civil Rights<br> <input type=checkbox name=option[] value="Military History">MilitaryHistory<br> <input type=submit name=submit value=Submit> and mailform2.php containing: echo "you selected: <br>"; /* line 81 */ foreach ($_POST[option] as $a)Turn notices on. You will then get lots of notices about the use of an undefined constant "option". You should be using $_POST['option'] instead - notice the quotes. Your HTML should really have double quotes around the attributes but that's beyond the scope of this list.{ echo "$a"; }but I'm getting the error: you selected: *Warning*: Invalid argument supplied for foreach() in */var/www/sites/mdah-test/museum/mmhsurvey/mailform2.php* on line *81* I googled some checkbox/foreach pages on google, but I don't see where I'm going wrong. I'm running php 5.2.5 on Apache 2.2.4 on Fedora Linux. Any help?