1

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 ?

5
  • what is the type of column aid? Commented Feb 25, 2013 at 4:30
  • change aid to autoincrement in database table will fix the issue. Commented Feb 25, 2013 at 4:31
  • Well, @Madan Sapkota, I'm checking it.. Commented Feb 25, 2013 at 4:32
  • @Madan Sapkota It's already set to autoincrement. Commented Feb 25, 2013 at 4:33
  • @BabuAhmed, i posted the answer. Commented Feb 25, 2013 at 4:37

6 Answers 6

2

Probably that DB has differents settings than your local. STRICT_TRANS_TABLES mode might be turned on. Try SELECT @@GLOBAL.sql_mode; and SELECT @@SESSION.sql_mode;.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

Thanks @Starx Working with your first statement. But I already set aid column to primary key and autoincrement. So why your second statement is not working ?
And I upload it(my code) to another server BUT It's working fine!
0

aid is a column that is an integer, and you're trying to insert '' into it. '' is not a number, so the insertion fails.

Perhaps there's a server setting to auto-convert the incorrect type, but you shouldn't rely on it (as you've just found out)

Comments

0

This causes the error aid(INT) - which is included on you table columns(first column).

If its auto increment remove the ''.

$insert = mysql_query("INSERT INTO brt_articles VALUES('$post_title', '$des', 
'$date', '$org_date')");  

Regards

2 Comments

It's a autoincrement field.
you should not be adding a value if its auto increment field.
0

try

"INSERT INTO brt_articles VALUES('".$post_title."', '".$des."', '".$date."', '".$org_date."')"

Remove first '' it's not needed as MySQL automatically add it if its primary key and auto_increment.

Comments

0

your local db has the value of that column set to auto increment or has a default value.

on the server db, the table definition is not the same.

review and compare the table definitions and then make them consistent.

2 Comments

if he uploaded the local database tables to server, then your statement is not true.
thanks - now i see the nonexistent text where he says he uploaded the local database tables to the server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.