HTML复选框表单php

时间:2013-03-04 15:05:35

标签: php

您好Html表单发送0而不是1到我的数据库有问题,它被设置为tinyint 1 我已经搞砸了好几天了。

我使用phpmyadmin xampp服务器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>

有人可以帮忙吗?

罗布

3 个答案:

答案 0 :(得分:0)

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

AND:移至mysqli或PDO,不推荐使用mysql。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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