473,512 Members | 14,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkboxes, $_POST array, and switch statement

I'm having problems with a switch statement that is wrapped in a
foreach statement so that each index in an array is evaluated against
the switch statement. The switch/case will then return some output for
display.

I have a long list of classes for the upcoming semester. Each one has a
checkbox to the right that has the following code. <input
type="checkbox" name="course[]" value="i"> where i increases linearly
with each class, i.e. first class value="1" second value="2". There are
41 classes for the semester. Upon submission of the form (Yes, I have a
<form> tag with all the necessary parameters.), display.php (the action
of the form) should loop through each key in the course array and
evaluate the value against a switch statement. Here is what my PHP code
looks like so far:

if(isset($_POST['course']) {
foreach ($_POST['course'] as $key => $value) {
switch($value)
case 1:
echo 'foo';
break;
case 2:
echo 'bar';
break;
default:
echo 'Please select a course';
break
.............

I tried putting the case numbers in quotes like

case "1":

but that didn't make any different. What this will eventually do is
pull book information for each class that is selected from Amazon and
enable the user to quickly add the books to a shopping cart and check
out. I shortened the code (leaving out the other 39 cases!) and I
omitted the html that the PHP page contains. Can anyone explain what I
am doing wrong with my switch statement and/or array?

Jan 11 '06 #1
1 5022
ljb, thanks for your kind response. As John Reuben would say, "Thanks
to everyone who chose to bite their tongue instead of busting us out;
you could have made us look dumb. But you didn't, and I appreciate the
courtesy..." I keep telling people I know just enough PHP to be
dangerous and annoying.

Jan 11 '06 #2

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

Similar topics

35
8292
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
2
4387
by: MJ | last post by:
Hi We can use the switch statement, or if else statement instead of switch One more method is there which can replace the switch using the function pointer or the array of function pointer. If...
2
7654
by: Macca | last post by:
Hi, I have a switch statement that has 5+ case statements. Each of these case statements copies form one array to another. Rather than doing a separate try..catch statement for each case...
7
22111
by: priyanka | last post by:
Hi there, I had a question. Is there any way of testing a string value in a switch statement. I have about 50 string values that can be in a string variable. I tried cheking them with the if...
10
2416
by: anon.asdf | last post by:
Here's a reminder of duff's device: /*************************************/ #include <stdio.h> #define STEP 8 #define MAX_LEN STEP*4+1 #define SOURCE_LEN 28
7
14541
by: =?Utf-8?B?Sm9zZXBo?= | last post by:
I would like to know how to implement several Radiobuttons using the Switch statement instead of If/Else conditional statement. For instance, if I have the following: if (RadioButton1.Checked =...
2
1543
by: Blip | last post by:
I try to update the buffer pointer in a switch statement like this: buf=(serialinput); switch (buf) that doesn't work correctly -- doesn't update the ptr I changed it to:...
10
8448
by: stewdizzle | last post by:
I am setting up a small site for personal use. It consists of a form that transfers inputed values to an html template. The ouput is code that i can use to quickly post on a website. In the...
1
1237
by: Frakes | last post by:
I'm using a hyperlink to pass a value from a home page to a search page. I'm using to values to identify and display only certain input/select boxs that relate to whatever unique search the user...
0
7254
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
7153
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
7432
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...
1
7094
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
7519
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...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.