HTML复选框表格php
问题描述:
你好我有一个Html表单发送0而不是1到我的数据库的问题,它被设置为tinyint 1 我一直在搞这个好几天。HTML复选框表格php
我用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"/> <input type="submit" value="Send" />
</center>
谁能帮助?
罗布
答
设置复选框value="1"
,否则串"driving_license"
传递到您的DB-场是tinyint
:-(
和:移动到库MySQLi或PDO,MySQL是过时
+0
谢谢你会做 – pitbull10 2013-03-04 15:15:44
答
,最好使用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"/> <input type="submit" value="Send" name="submit" />
</center>
我就不会担心了0/1的东西,担心张开大开[SQL注入漏洞(HTTP://鲍比桌。 com)在你的代码中。但请记住,表单中未选中的复选框在提交表单时通过网络发送** NOT **。 – 2013-03-04 15:07:59
[**请不要在新代码中使用'mysql_ *'函数**](http://bit.ly/phpmsql)。他们不再被维护[并且被正式弃用](http://j.mp/XqV7Lp)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 – 2013-03-04 15:08:05
我认为你的tinyint列的默认值为0,现在试图将字符串添加到此列。 – Tim 2013-03-04 15:08:33