Hi there,

Just wondering if there is a way of inserting tuples into a table without specifying the primary key id.

insert into myTable (username, password) values (value1, value2);

Ok. When I use the above mentioned statement, it complains about duplicate keys. Anyone know why? shouldn't the key be generated automatically?

Thank you.

When creating your table, did you specify the ID (primary_key) was auto increment? If so, you shouldn't have this problem..

In phpmyadmin you can tick a box that says auto increment otherwise you can explicitly define it with an SQL statement.

Member Avatar
diafol

Maybe you can use the SET syntax:

mysql_query("INSERT INTO myTable SET `username` = '$value1', `password` = '$value2'");