当我尝试提交此错误时,有谁可以看到我收到以下错误的原因?我知道整个零vs''的事情,但我没有任何''应该导致这个。 mySQL新手,所以任何帮助都会很棒。
第1行第2列的错误整数值=''
<?php
$db_host = "localhost";
$db_username = "TEST";
$db_pass = "example";
$db_name = "questions";
@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No database");
if ($_POST['parse_var'] == "contactform"){
$oneField = $_POST['one'];
$twoField = $_POST['two'];
$threeField = $_POST['three'];
$noneField = $_POST['none'];
$surveyField = $_POST['survey'];
$questionField = $_POST['questions'];
$guestField = $_POST['guest'];
$homeField = $_POST['home'];
$selected_radio = $_POST['radio'];
if ($selected_radio == 'one')
{
$oneField = '1';
}
else if ($selected_radio == 'two')
{
$twoField = '1';
}
else if ($selected_radio == 'three')
{
$threeField = '1';
}
else if ($selected_radio == 'none')
{
$noneField = '1';
}
if($surveyField == "yes"){
$surveyField = "1";
}
if($mysqlField == "yes"){
$mysqlField = "1";
}
if($guestbookField == "yes"){
$guestbookField = "1";
}
if($homeField == "yes"){
$homeField = "1";
}
$sqlUpdate = mysql_query("INSERT INTO questiondata (one, two, three, none, survey,
question, guest, home)
VALUES ('$oneField','$twoField','$threeField','$noneField','$surveyField','$questionField','$guestField','$homeField')")
or die (mysql_error());
}
?>
答案 0 :(得分:1)
列“two”是一个整数列,显然你正试图在其中插入一个空字符串。
检查空字符串,并用其他值替换它们或null(如果列可以为空)
$twoField = $_POST['two'];
if (empty($twoField))
{
$twoField = 0;
}
PS:我建议其他领域也这样做。
答案 1 :(得分:1)
你试图INSERT
,其中一个整数参数为空,即:
INSERT INTO questiondata (one, two) VALUES ('1','')
除非one
或two
是字符串字段,否则无效
修改您的代码,以便初始化空变量:
$oneField = isset($_POST['one']) ? $_POST['one'] : 0;
$twoField = isset($_POST['two']) ? $_POST['two'] : 0;