...

View Full Version : Returning Primary Key



jlimited
11-18-2006, 10:28 PM
Hello,

My mysql table is setup as the following:

billingid (Primary Key, auto_increment)
userid
billingdate
invoice

I have a script that is inserting data into a mysql database table.

mysql_query("INSERT INTO billing SET userid='$userid', billingdate='$billingdate', invoice='$invoice'");

What I want to know is if there is a way to return the billingid value for the row that is inserted without querying the database for the record?

For Example:

mysql_query("INSERT INTO billing SET userid='$userid', billingdate='$billingdate', invoice='$invoice' RETURN billingid");


Thanks
jlimited

boeing747fp
11-18-2006, 10:30 PM
as long as you have `billingid` as an AUTO INCREMENT field, use mysql_insert_id() (http://us2.php.net/manual/en/function.mysql-insert-id.php)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum