整数值不正确:''表示列错误

时间:2011-12-08 18:21:22

标签: php mysql

我为'country_id列'获取'不正确的整数值:''。有时我的下拉列表会隐藏在表单中。所以我不知道如何处理这种情况。这是我的代码。谢谢你的帮助。

$countryId = isset($_POST['country']) ? $_POST['country'] : 0;

$inserSQL = "INSERT INTO Table1(country_id) VALUES('" .$countryId. "')";

$Result1 = mysql_query($inserSQL ) or die(mysql_error());

2 个答案:

答案 0 :(得分:4)

您要将'添加到$countryId值。由于需要整数,因此您不必使用它们。试试这个:

$countryId = isset($_POST['country']) ? (int)$_POST['country'] : 0;

$inserSQL = "INSERT INTO Table1(country_id) VALUES($countryId)";

$Result1 = mysql_query($inserSQL ) or die(mysql_error());

答案 1 :(得分:0)

我曾经遇到此问题,显然我打错了,而不是输入0而不是键入O“ Letter O”,并且该值在数据库中是不希望的,因为该数据库字段仅被接受整数。

请确保您从代码中传递的值是整数类型。