0

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.

4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by diafol
0

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

0

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

0

Maybe you can use the SET syntax:

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

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.