[SOLVED] Need some help here with checkboxes
Posted: Sun Jul 17, 2011 7:15 pm
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> </td>
<td> </td>
<td> </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:
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
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> </td>
<td> </td>
<td> </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!";
}
?>
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