Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2004, 07:04 PM   PM User | #1
ew1
New Coder

 
Join Date: Mar 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ew1 is an unknown quantity at this point
checkboxes and variable variables into MySQL

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.
ew1 is offline   Reply With Quote
Old 10-06-2004, 07:46 PM   PM User | #2
Dylan Leblanc
Regular Coder

 
Join Date: Sep 2002
Location: British Columbia
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Dylan Leblanc is an unknown quantity at this point
You are getting all those zeros because you are adding strings together. Strings are supposed to be contatenated with the period.
__________________
http://skyscraperpage.com/
Dylan Leblanc is offline   Reply With Quote
Old 10-12-2004, 03:40 PM   PM User | #3
ew1
New Coder

 
Join Date: Mar 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ew1 is an unknown quantity at this point
Whoops! I was thinking in java, not php. Thanks!
ew1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:46 AM.


Advertisement
Log in to turn off these ads.