0

您好,我有一个 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>

任何人都可以帮忙吗?

4

3 回答 3

0

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

于 2013-03-04T15:43:40.873 回答
0

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

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

于 2013-03-04T15:11:15.287 回答
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>
于 2013-03-04T16:20:50.113 回答