nav100
nav100

Reputation: 3133

Incorrect integer value: '' for column error

I am getting 'Incorrect integer value: '' for column country_id'. Sometimes my dropdown is hidden in the form. So I am not sure how to handle this situtation. Here is my code. Thanks for any help.

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

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

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

Upvotes: 1

Views: 20593

Answers (2)

Tadiwanashe
Tadiwanashe

Reputation: 1304

I once experienced this problem and apparently i had a typo instead of putting a 0 i typed an O "Letter O" and that value was not expected in the database because the database field only accepted integers.

Make sure in your the value being passed from your code is integer type.

Upvotes: 0

emco
emco

Reputation: 4709

You are adding ' to the $countryId value. Since an integer is expected, you don't have to use them. Try this:

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

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

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

Upvotes: 6

Related Questions