If I have a table named MUSIC:
ID SONG ARTIST
1 Gum Tim
2 Air Bob
How can I insert a row with autoincrement ID?
INSERT INTO MUSIC (ID, SONG, ARTIST)
VALUES (,earth, mark);
If I have a table named MUSIC:
ID SONG ARTIST
1 Gum Tim
2 Air Bob
How can I insert a row with autoincrement ID?
INSERT INTO MUSIC (ID, SONG, ARTIST)
VALUES (,earth, mark);
As long as ID is your autoincrement this should work. You don't need to declare it in your field listing.
INSERT INTO MUSIC (SONG, ARTIST) VALUES (earth, mark);
ID field should be "autoincrement", read more here
And in case it's already autoincroment:
INSERT INTO MUSIC (SONG, ARTIST) VALUES ('Yesterday', 'Beatles');
You'll have to set the table in sql to have a primary key. It isn't PHP's job to create the key. Then, if you need the primary key, do something like this:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>
Source: http://php.net/manual/en/function.mysql-insert-id.php