View Full Version : PHP and checkboxes Driving me crazy!!!

08-25-2006, 12:56 AM
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:


The php script itself can be tested at:


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.


08-25-2006, 02:06 AM
Try testing the $_POST values of your checkboxes with !empty...i.e.,

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

08-25-2006, 04:39 AM
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.