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')

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!