Checkboxes, $_POST array, and switch statement

This is a discussion on Checkboxes, $_POST array, and switch statement within the PHP Language forums, part of the PHP Programming Forums category; I'm having problems with a switch statement that is wrapped in a foreach statement so that each index in ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-11-2006
Berko
 
Posts: n/a
Default 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?

Reply With Quote
  #2 (permalink)  
Old 01-11-2006
Berko
 
Posts: n/a
Default Re: Checkboxes, $_POST array, and switch statement

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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0