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

nav*_*100 0 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());
Run Code Online (Sandbox Code Playgroud)

EmC*_*mCo 5

要添加'$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());
Run Code Online (Sandbox Code Playgroud)