Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    ew1
    ew1 is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are getting all those zeros because you are adding strings together. Strings are supposed to be contatenated with the period.

  • #3
    ew1
    ew1 is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops! I was thinking in java, not php. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •