problem with array in html <option> form
Posted: Wed Oct 11, 2006 1:39 pm
Hi guys. I am reading the learning php5 book and the following bit of code is used in one of the examples. However, when I run it I get the error:
Warning: Invalid argument supplied for foreach() in C:\wamp\www\Tests\test.php on line 40
I can select a single value from the option box and it will print it but I can't select multiple options and print them all by using the foreach function.
ANy idea why this is?
thanks alot
Warning: Invalid argument supplied for foreach() in C:\wamp\www\Tests\test.php on line 40
I can select a single value from the option box and it will print it but I can't select multiple options and print them all by using the foreach function.
ANy idea why this is?
thanks alot
Code: Select all
<form method="POST" action="test.php">
<select name="lunch[]" multiple>
<option value="pork">BBQ Pork Bun</option>
<option value="chicken">Chicken Bun</option>
<option value="lotus">Lotus Seed Bun</option>
<option value="bean">Bean Paste Bun</option>
<option value="nest">Bird-Nest Bun</option>
</select>
<input type="submit" name="submit">
</form>
Selected buns:
<br/>
<?php
foreach ($_POST['lunch'] as $choice) {
print "You want a $choice bun. <br/>";
}
?>