473,671 Members | 2,473 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 5031
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
8334
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 for '5'. So in his switch statement, he omits a case for '5':
2
4401
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 any one has any idea how to do it , could guide me MJ
2
7663
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 statement I wanted to wrap all the case statements in one try catch statement. However I am having problems doing this as there is a compilation error wrapping all the case statements inside the try block or putting the whole switch statement in the...
7
22127
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 else statements but it looked pretty ugly and the string values to be tested is still increasing. The switch statement seems to be a better choice then the if else statement. But it seems that the switch statement accepts integer values as the test...
10
2427
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
14573
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 = true) { //Do something; } elseif(RadioButton2.Checked = true) {
2
1559
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: buf=(serialinput); switch (buf)
10
8498
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 template i have the following code: <?php $images = $_POST; switch ($images) { case 1: echo '<img src="http://i43.tinypic.com/29z3eyo.jpg">'; break; case 2: echo '<img src="http://i43.tinypic.com/29z3eyo.jpg"> &nbsp;
1
1243
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 wants to use. I've gotten the value from "TYPE=VALUE" to display in my search page but now I'm wondering if it will work for my switch statement since none of my document.write statements are working. Home Page links: <BODY> ...
0
8483
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8603
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8673
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6236
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2818
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 we have to send another system
2
1815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.