HTML复选框表单php


HTML checkbox form php

你好,我有一个Html表单发送0而不是1到我的数据库的问题,它被设置为tinyint 1我已经摆弄这个好几天了。

我使用phpmyadmin xampp server html php

<!--THIS IS SKILLS-->
 <?php

 $con = mysql_connect("localhost","root","");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
if (!isset($_POST['action'])) 
 mysql_select_db("client", $con);
$sql="INSERT INTO skills (driving_licence,HGV,engineer,carpenter,chef,PSV)
 VALUES
 ('$_POST[driving_licence]','$_POST[HGV]','$_POST[engineer]','$_POST[carpenter]','$_POST[chef]','$_POST[PSV]')";
 if (!mysql_query($sql,$con))
   {
   die('Error: ' . mysql_error());
   }
 echo "skills have been added";
 mysql_close($con);
 ?>

表单代码为

<center><form method="post" action="skills.php">
<table cellspacing="50">
<tr>
<center><h1>Record Client Skills</h1></center>
<center><p> Please choose the relevent boxes</p></center>

<center><input type="checkbox" name="driving_licence" value="driving_licence">I have a Full UK Driving Licence<br>
 <input type="checkbox" name="hdv" value="hgv">I hold a valid a HGV licence<br> 
 <input type="checkbox" name="engineer" value="engineer">I have an Engineering qualification <br>
 <input type="checkbox" name="carpenter" value="carpenter">I have a Carpentry qualification <br>
 <input type="checkbox" name="chef" value="chef">I have Catering qualification<br>
 <input type="checkbox" name="psv licence" value="psv">I have a valid PSV licence<br>   
</tr>   
</table>
<input type="reset" value="Reset Form"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <input type="submit" value="Send" />

 </center>

有人能帮忙吗?

Rob

设置复选框value="1",否则字符串"driving_license"将传递到您的db-field,即tinyint:-(

)

最好使用bit(1)而不是tinyint布尔值,不要使用root连接到mysql并使用PDO或Mysqli,最后它不是为用户打印mysql错误的好方法,使用php数据库类之一

<?php

 $con = mysql_connect("localhost","root","");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
if (isset($_POST['submit'])) 
{
 mysql_select_db("client", $con);
$sql="INSERT INTO skills (driving_licence,HGV,engineer,carpenter,chef,PSV)
 VALUES
 ('$_POST[driving_licence]','$_POST[HGV]','$_POST[engineer]','$_POST[carpenter]','$_POST[chef]','$_POST[PSV]')";
 if (!mysql_query($sql,$con))
   {
   die('Error: ' . mysql_error());
   }
 echo "skills have been added";
 mysql_close($con);
}
 ?>

你的Html表单——

<center><form method="post" name="f1" action="skills.php">
<table cellspacing="50">
<tr>
<center><h1>Record Client Skills</h1></center>
<center><p> Please choose the relevent boxes</p></center>
<center><input type="checkbox" name="driving_licence" value="driving_licence">I have a Full UK Driving Licence<br>
 <input type="checkbox" name="hdv" value="hgv">I hold a valid a HGV licence<br> 
 <input type="checkbox" name="engineer" value="engineer">I have an Engineering qualification <br>
 <input type="checkbox" name="carpenter" value="carpenter">I have a Carpentry qualification <br>
 <input type="checkbox" name="chef" value="chef">I have Catering qualification<br>
 <input type="checkbox" name="psv licence" value="psv">I have a valid PSV licence<br>   
</tr>   
</table>
<input type="reset" value="Reset Form"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <input type="submit" value="Send" name="submit" />
</center>