ew1
10-06-2004, 07:04 PM
Hello,
I am having some trouble with a form which consists of a number of courses, each of which has a checkbox to choose it. I have each checkbox formed with the following code:
<input type="checkbox" name="chosenClass[]" value="1" /> Course 1
<input type="checkbox" name="chosenClass[]" value="2" /> Course 2
<input type="checkbox" name="chosenClass[]" value="3" /> Course 3
<input type="checkbox" name="chosenClass[]" value="4" /> Course 4
The reason I chose to use the array as the name is because I got my javascript validation to work with it. (I know, it's sad :( ). It will alert the user if they have not checked at least one checkbox.
When the user hits 'submit', the data gets sent to the next php page (via POST). There, I try to extract the data from the stream like so:
foreach($_POST['chosenClass'] as $key => $value)
{
print $varname + " = $varname before";
print $varname + " = $key before";
print $varname + " = $value before";
$varname = "session".$key;
$$varname = $value;
print $varname + " = $varname after";
print $varname + " = $key after";
print $varname + " = $value after";
print "************";
}
The print statements are for testing.
What I get is this:
000000************000000************000000************
Does anyone have any idea of what I'm doing wrong? I'm using a variable variable.
Ideally, I wanted to just be able to capture a number or boolean value so that I can push this into a table in MySQL.
Help!!
Much obliged to you all.
:)
I am having some trouble with a form which consists of a number of courses, each of which has a checkbox to choose it. I have each checkbox formed with the following code:
<input type="checkbox" name="chosenClass[]" value="1" /> Course 1
<input type="checkbox" name="chosenClass[]" value="2" /> Course 2
<input type="checkbox" name="chosenClass[]" value="3" /> Course 3
<input type="checkbox" name="chosenClass[]" value="4" /> Course 4
The reason I chose to use the array as the name is because I got my javascript validation to work with it. (I know, it's sad :( ). It will alert the user if they have not checked at least one checkbox.
When the user hits 'submit', the data gets sent to the next php page (via POST). There, I try to extract the data from the stream like so:
foreach($_POST['chosenClass'] as $key => $value)
{
print $varname + " = $varname before";
print $varname + " = $key before";
print $varname + " = $value before";
$varname = "session".$key;
$$varname = $value;
print $varname + " = $varname after";
print $varname + " = $key after";
print $varname + " = $value after";
print "************";
}
The print statements are for testing.
What I get is this:
000000************000000************000000************
Does anyone have any idea of what I'm doing wrong? I'm using a variable variable.
Ideally, I wanted to just be able to capture a number or boolean value so that I can push this into a table in MySQL.
Help!!
Much obliged to you all.
:)