PHP MYSQL - Insert into without using column names but with autoincrement field

Viewed 44755

I need to insert a long row with 32 fields into a MySQL table.

I'd like to do something like this:

$sql="insert into tblname values (... 32 fields ...)";

Obviously, it works fine if the fields are in the same order as the MySQL table fields. But, my table has an auto-increment id as it's first field.

What I want is to fill in all table names but the first (id) one.

Suggestions?

5 Answers

Use NULL or 0 to insert an auto-incremented value as shown below:

                         -- Here
INSERT INTO tblname VALUES (NULL, ... 32 Fields ... )
                         -- Here
INSERT INTO tblname VALUES (0, ... 32 Fields ... )
Related