K.Wayne K.Wayne - 3 months ago 13
MySQL Question

How to add Varchar checkbox values in MySql?

I'm trying to add Varchar values from checkbox to mysql and it adding string "1" in the checked checkboxes. How I can make it to add Varchar values like below?

<?php
if (isset($_POST['dr_add'])) {
$lightv = isset($_POST['l_vehicle']);
$van = isset($_POST['van']);
$truck = isset($_POST['truck']);
$trailer = isset($_POST['tr_trailer']);
mysql_query("INSERT INTO driving(user_id, country,l_vehicle,van, truck , tr_trailer) VALUES('$user->employeeid','$lightv','$van','$truck','$trailer')") or die(mysql_error());
}
?>
<input type="checkbox" name="l_vehicle" value="Light Vehicle"/>Light Vehicle
<input type="checkbox" name="van" value="Van">Van
<input type="checkbox" name="truck" value="Truck"/>Truck
<input type="checkbox" name="tr_trailer" value="Truck&Trailer"/>Truck&Trailer

Answer

You are using $trailer = isset($_POST['tr_trailer']); and it is wrong :

User below code :

 $trailer = isset($_POST['tr_trailer'])?$_POST['tr_trailer']:"";

Use this for all checkboxes

Comments