Page 1 of 1

[SOLVED] Need some help here with checkboxes

Posted: Sun Jul 17, 2011 7:15 pm
by butlerjw
Ok, I am developing a job application form. I have 8 checkboxes to represent Yes if checked, No if not checked.
In my table in mysql I have set these to tinyint(1) with a defined value of 0

Here is my form snipit
[text] <tr>
<td><u>Check All that apply:</u></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Owner Operator
<input type="checkbox" name="inputownerop" value="1" />
</td>
<td>Independent Driver
<input type="checkbox" name="inputidriver" value="1" />
</td>
<td>Class A CDL
<input type="checkbox" name="inputclass_a" value="1" />
</td>
<td>Class B CDL
<input type="checkbox" name="inputclass_b" value="1" />
</td>
</tr>
<tr>
<td>Hazmat
<input type="checkbox" name="inputhazmat" value="1" />
</td>
<td>Team Driver
<input type="checkbox" name="inputteam" value="1" />
</td>
<td>Solo Driver
<input type="checkbox" name="inputsolo" value="1" />
</label></td>
<td>Husband and Wife
<input type="checkbox" name="inputhuswife" value="1" />
</td>
</tr>
[/text]


And here is my code snipit:

Code: Select all

<?php
     	include 'include/connections.php';

        $lname = $_POST['inputlname'];
        $fname = $_POST['inputfname'];
        $email = $_POST['inputemail'];
        $phone = $_POST['inputphone'];
        $add1 = $_POST['inputadd1'];
        $add2 = $_POST['inputadd2'];
        $city = $_POST['inputcity'];
        $state = $_POST['inputstate'];
        $zip = $_POST['inputzip'];
        $ownerop = $_POST['inputownerop'];
        $idriver = $_POST['inputidriver'];
        $class_a = $_POST['inputclass_a'];
        $class_b = $_POST['inputclass_b'];
        $hazmat = $_POST['inputhazmat'];
        $huswife = $_POST['inputhuswife'];
        $solo = $_POST['inputsolo'];
        $team = $_POST['inputteam'];

        if(!$_POST['submit']) {
                echo "please fill out the form";

        } else {
                mysql_query("INSERT INTO applications (`id`, `fname`, `lname`, `phone`, `email`, `add1`, `add2`, `city`, `state`, `zip`, `ownerop`, `idriver`, `class_a`, `class_b`,$
`huswife`,
`solo`, `team`)
                        VALUES(NULL, '$fname', '$lname', '$phone', '$email', '$add1', '$add2', '$city', '$state', '$zip', '$ownerop', '$idriver', '$class_a', '$class_b', '$hazmat',$
'$solo', '$team')") or die(mysql_error());
         echo "User has been added!";


        }
?>
In the above code, everything is working and is being put in the database, but it fails when I hit ownerop, idriver and so on. The last bit of code is my check boxes.

If I actually check the box in my test, I do not get any errors, but it does not update the database to show a value of 1 for true. All the values remain set to 0.
If the boxes are unchecked, they all fail.

Thanks
Jim

Re: Need some help here with checkboxes

Posted: Sun Jul 17, 2011 8:43 pm
by butlerjw
Not sure what I did, but I seem to have gotten it to work correctly.

Re: Need some help here with checkboxes

Posted: Mon Jul 18, 2011 7:11 am
by maneetpuri
Hi,

When a checkbox is not checked the variables respective to it does not get created, and this what is creating the problem. No using isset function you can check if the variable is not set then set its value to zero and your problem will be resolved.

Cheers,

~Maneet

Re: [SOLVED] Need some help here with checkboxes

Posted: Mon Jul 18, 2011 11:45 pm
by butlerjw
Thanks!!