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
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP and checkboxes Driving me crazy!!!

    I have a registration form that I'm coding in php and I have 3 checkboxes named 'R1Info', 'R2Info' and 'R3Info' with no values specified, so if my understanding is correct, php interprets a checked checkbox with no value as 'on'. In my php code, I'm using $_SESSION and assigning this variable with the value of $_POST ie $_SESSION['R1Info'] = $_POST['R1Info'] and sometimes the checkbox either when it's checked, or it's not checked changes the value of $_SESSION['R1Info'] and $_POST['R1Info'] the values change from either blank, '1', and 'on'. Sometimes when the checkbox is checked, it gives me a value other than 'on'. Also, I'm having the same troubles with the select box. You can see a text copy of the script at:

    http://www.spanishmania.ca/siregisterftest.txt

    The php script itself can be tested at:

    http://www.spanishmania.ca/siregisterftest.php

    all of the $_POST variables are currently printed at the top for debugging and just below is the $_SESSION variables. they are labled like this 'VARIABLE ->fnr1' would represent 'First Name of the first registrant' notice how the $_SESSION variables differ from the $_POST Variables. I don't beleive that they should as I set $_SESSION with $_POST.

    If someone could take a look at my code and please guide me in the right direction, it would be greatly appreciated. Also, this is my first php script that I have written without copying code from other scripts, so I appologize if it seems a bit messy.

    Thanks,
    Titanic_Fanatic

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,793
    Thanks
    19
    Thanked 156 Times in 147 Posts
    Try testing the $_POST values of your checkboxes with !empty...i.e.,

    PHP Code:
    if (!empty($_POST['checkbox']))
    {
          
    // Do something here if checkbox is checked.

    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i figured it out... when I was using an if statement, I would sometimes use = instead of == to compare, and in the process it was resetting the value of each of the feilds.


  •  

    Posting Permissions

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