473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Book example doesn't work here

I am trying the example of the book "Learning PHP5", here's an example
that doesn't work here. It's a simple array sent from a form, and I
want to display values sent, but if I select several meals from the
form, only the last one is displayed:

<form method="POST" action="eat.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/>";

}

?>

On the book it says it should print all selected items. Here it
displays only the last one. I'm sure all are selected, because I hold
down the "Ctrl" key while selecting the options.
Any idea?
Thanks,

Sep 7 '06 #1
3 1197

Charles wrote:
I am trying the example of the book "Learning PHP5", here's an example
that doesn't work here. It's a simple array sent from a form, and I
want to display values sent, but if I select several meals from the
form, only the last one is displayed:

<form method="POST" action="eat.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/>";

}

?>

On the book it says it should print all selected items. Here it
displays only the last one. I'm sure all are selected, because I hold
down the "Ctrl" key while selecting the options.
Any idea?
Thanks,
Remove the spaces in between the [ and ] in the <selectelement:

<select name="lunch[]" multiple>

Sep 7 '06 #2

ZeldorBlat wrote:
Remove the spaces in between the [ and ] in the <selectelement:
Thanks! Wow, a little detail, really :)

Sep 7 '06 #3
On 7 Sep 2006 10:54:16 -0700, "Charles" <la********@gmail.comwrote:
>I am trying the example of the book "Learning PHP5", here's an example
that doesn't work here. It's a simple array sent from a form, and I
want to display values sent, but if I select several meals from the
form, only the last one is displayed:

<form method="POST" action="eat.php">

<select name="lunch[ ]" multiple>
There should be no spaces between the [ and ], else you end up with a single
key consisting of that many spaces, instead of an array of values.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Sep 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
1
by: David Thompson | last post by:
Looking for a book to help me develop a philosophy for building databases (particularly on MySQL). And then taking them from concept to construction. Something like.... Start by asking which...
3
by: Java script Dude | last post by:
I have still yet to see a JavaScript Editor that comes close to reading a good JS book, learing it and using it with a text editor. Anyway, here my recipe for build successfull DHTML...
3
by: Tony Johansson | last post by:
Hello! I want to say that I rather new to C# have only worked with it for 5 month. I'm now reading a book and there are some example on the internal key work that doesn't work as the book...
3
by: xllx.relient.xllx | last post by:
I have a question about an example presented in the book "INFORMIT C++ Reference Guide" by Danny Kalev: <code> string getmagicword() ( return string("Supercalifragilisticexpialidocious"); );
24
by: Noah Roberts | last post by:
Item #1 in the More Exceptional C++ book uses the following construct: fstream in; .... process( in.is_open() ? in : cin,...); Where process has been shown as having various multiple...
11
by: www.douglassdavis.com | last post by:
I'm looking for advice here, and I would really appreciate it if you could help. Is there a VB 2005 book that you like and would recommend (and why)? Would you consider it good for...
7
by: simonZ | last post by:
I would like to buy a book with some windows application example in C# net , but all books I have found are only about theory. I would like to have a book, where is explained how to create...
76
by: lorlarz | last post by:
Crockford's JavaScript, The Good Parts (a book review). This shall perhaps be the world's shortest book review (for one of the world's shortests books). I like Douglas Crockford (because I am a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.