February 25, 2013
Sql Error – Incorrect integer value
Question by Babu Ahmed
I’m getting following error when I submit a form:
Can't added a new post. Incorrect integer value: '' for column 'aid' at row 1
Php Code:
$insert = mysql_query("INSERT INTO brt_articles VALUES( '', '$post_title', '$des',
'$date', '$org_date')");
if($insert)
{
echo "<font color=green>Successfully added a new article.</font>";
header("Refresh:3; url=allbrtarticle.php");
}
else
{
echo "<font color=red>Can't added a new post</font>" .
mysql_error();
}
In my Localhost It’s ok. But in server why it’s giving me a error message ?
Answer by Starx
The aid
field does not accept ''
value as input.
The safest way is to specify column names as you are sending the query.
INSERT INTO brt_articles (title_field, description_field, date_field, org_date, fieldname) VALUES('$post_title', '$des', '$date', '$org_date');
If aid
is a primary key, simply omit that field in your query
INSERT INTO brt_articles VALUES('$post_title', '$des', '$date', '$org_date')