PDA

View Full Version : [SOLVED] Get Auto Id From Newly Inserted Item MySQL



mike_g
June 8th, 2008, 10:15 PM
I have an 'order' table in a mysql database which links to an 'item' table via an auto increment field in the 'order' table.

When I create a new order I want to be able to get the auto id assigned to it so that I can add items that link to it. Heres the code I have so far:

$date = date("F j, Y, g:i a");
$link = mysql_connect($localhost, $username, $password);
mysql_select_db($database);
mysql_query(" INSERT INTO order(email, date) VALUES($email, $date)");
Can anyone tell me how I would be able to get it? Cheers.

geirha
June 8th, 2008, 10:49 PM
mysql_insert_id (php.net/mysql_insert_id)