Auto Increment & MySQL

Soldato
Joined
14 Feb 2006
Posts
4,644
Location
Surrey, UK
Code:
$query = "INSERT INTO articles VALUES ('','$author','$headline','$article','0','0')";
mysql_query($query);

The first field ("id") is set to auto increment, so when added a new record, the field is left blank.

However, MySQL returs:
Code:
#1366 - Incorrect integer value: '' for column 'id' at row 1

Anyone know why this is? It works fine if I specify an integer for the "id" field, but in theory it should do this automatically, shouldn't it?

TIA, Jon
 
if you specify the column names for the other fields, then the auto increment thing will work on it's own without specifying it eg....

Code:
$query = "INSERT INTO articles(author, headline, article, blah, bleh) VALUES ('$author','$headline','$article','0','0')";

there might be an easier/better way. i only know very basic mysql... :p
 
marc2003 said:
if you specify the column names for the other fields, then the auto increment thing will work on it's own without specifying it eg....

Code:
$query = "INSERT INTO articles(author, headline, article, blah, bleh) VALUES ('$author','$headline','$article','0','0')";

there might be an easier/better way. i only know very basic mysql... :p

Well it works, so I don't mind!

Thanks for replies both of you :D

Jon
 
Back
Top Bottom