我试图将Varchar值从复选框添加到mysql,并在选中的复选框中添加字符串“ 1”。我怎样才能像下面这样添加Varchar值?

<?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

最佳答案

您正在使用$trailer = isset($_POST['tr_trailer']);,这是错误的:

用户下面的代码:

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


将此复选框用于所有复选框

08-16 15:58