PHP mySQL - Insert new record into table with auto-increment on primary key PHP mySQL - Insert new record into table with auto-increment on primary key php php

PHP mySQL - Insert new record into table with auto-increment on primary key


Use the DEFAULT keyword:

$query = "INSERT INTO myTable VALUES (DEFAULT,'Fname', 'Lname', 'Website')";

Also, you can specify the columns, (which is better practice):

$query = "INSERT INTO myTable          (fname, lname, website)          VALUES          ('fname', 'lname', 'website')";

Reference:


I prefer this syntaxis:

$query = "INSERT INTO myTable SET fname='Fname',lname='Lname',website='Website'";


$query = "INSERT INTO myTable VALUES (NULL,'Fname', 'Lname', 'Website')";

Just leaving the value of the AI primary key NULL will assign an auto incremented value.