colap Posted February 24, 2011 Share Posted February 24, 2011 It's a mysql table. The first column is int(11) auto_increment not null primary key, I want to insert data into that table without specifying the first column name. What would be the sql query? The firs column is col1 with auto_increment.The value for the first column would be automatically inserted.Is it? insert into tablename(col2,col3) values("a","b"); Quote Link to comment https://forums.phpfreaks.com/topic/228689-how-can-i-insert-into-table-with-auto_increment-column/ Share on other sites More sharing options...
colap Posted February 24, 2011 Author Share Posted February 24, 2011 insert into tablename(col1,col2) values("a","b"); I got this error: Field 'id' doesn't have a default value. id is the auto_increment primary key column. Quote Link to comment https://forums.phpfreaks.com/topic/228689-how-can-i-insert-into-table-with-auto_increment-column/#findComment-1179063 Share on other sites More sharing options...
Muddy_Funster Posted February 24, 2011 Share Posted February 24, 2011 your first post had the correct syntax, your second post has you trying to insert the string value "a" into your auto_inc integer field. oh, and please use the tags when posting code up, makes life much easier. Quote Link to comment https://forums.phpfreaks.com/topic/228689-how-can-i-insert-into-table-with-auto_increment-column/#findComment-1179074 Share on other sites More sharing options...
ManiacDan Posted February 24, 2011 Share Posted February 24, 2011 Print the actual query, none of this "col2" and "tablename" stuff. Obviously your fake pseudo-query would work fine. Do a SHOW CREATE TABLE on the table, post that here. Do an INSERT on the table, post that here as well as the error. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/228689-how-can-i-insert-into-table-with-auto_increment-column/#findComment-1179084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.