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..

Member Avatar for iamthwee

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

Member Avatar for diafol

Maybe you can use the SET syntax:

mysql_query("INSERT INTO myTable SET `username` = '$value1', `password` = '$value2'");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.