...

View Full Version : checkboxes and variable variables into MySQL



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.
:)

Dylan Leblanc
10-06-2004, 07:46 PM
You are getting all those zeros because you are adding strings together. Strings are supposed to be contatenated with the period.

ew1
10-12-2004, 03:40 PM
Whoops! I was thinking in java, not php. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum