473,387 Members | 1,569 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,387 software developers and data experts.

Printing array items sent in a form

I'm trying an example from the book "Learning PHP5" but it doesn't
work as Expected. Snippet:

<form method="POST" action="index.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/>";
}
?>
When I select several itens with the Ctrl key, it still prints the
last item only, ie: "You want a nest bun."

I double-checked, and I selected several items. Any idea?
Thanks,

Feb 2 '07 #1
4 1587
ED

"Charles" <la********@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
I'm trying an example from the book "Learning PHP5" but it doesn't
work as Expected. Snippet:

<form method="POST" action="index.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/>";
}
?>
When I select several itens with the Ctrl key, it still prints the
last item only, ie: "You want a nest bun."

I double-checked, and I selected several items. Any idea?
Thanks,
hi Charles,
looks like you have space characters in the select name (between the square
brackets),
try: <select name="lunch[]" multiple>
and not: <select name="lunch[ ]" multiple>

cheers,
ED
Feb 2 '07 #2
Ok, I found out, there's gotta be only one space between the brackets
instead of two:

<select name="lunch[ ]" multiple>

Small detail. Big difference.

Feb 2 '07 #3
..oO(Charles)
>Ok, I found out, there's gotta be only one space between the brackets
instead of two:

<select name="lunch[ ]" multiple>
There's gotta be _no_ space!

<select name="lunch[]" multiple="multiple">

Micha
Feb 2 '07 #4
ED

"Michael Fesser" <ne*****@gmx.dewrote in message
news:q9********************************@4ax.com...
.oO(Charles)
>>Ok, I found out, there's gotta be only one space between the brackets
instead of two:

<select name="lunch[ ]" multiple>

There's gotta be _no_ space!

<select name="lunch[]" multiple="multiple">

Micha

Interestingly, it appears that this array syntax actually does work with a
single space (or a single tab character for that matter):

$foo = array();
$foo[] = 'empty';
$foo[ ] = 'space';
$foo[ ] = 'tab';
print_r($foo);

results in:
Array
(
[0] =empty
[1] =spacechar
[2] =tab
)strange huh?cheers, ED
Feb 2 '07 #5

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

Similar topics

0
by: LRW | last post by:
Subject line confusing? The whole thing is confusing to me. OK, I think the root of my problem, aside from mental, is array based...but I'm not even sure what I want to do is even possible. So if...
4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
1
by: NickB | last post by:
Please could someone tell me what is wrong. Ther error is: An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll Additional information: Object...
5
by: VMI | last post by:
I have a BMP image (the form is also in PDF) that contains a scanned copy of a paper form that we need to fill out. Is it possible to use this image in my application so that the application can...
8
by: Tinus | last post by:
Hello all, Because you have been so helpfull the last couple of times, I thought after testing and wasting more than 20 pages (and google-ling for 3 days :-( ). I would ask you again for your...
5
by: Tom | last post by:
I am converting an old application that was printing directly to a specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
2
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
7
by: Iain Wilson | last post by:
I am pulling my hair out trying to print various objects from a .net web page My apologies for cross posting but I need an answer and my previous post has attracted no interest. ASP.Net 2.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.