Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double insert and grab id 1

Status
Not open for further replies.

VAMick

Programmer
Nov 18, 2005
64
US
I need to insert data into two tables at the same time from a form for adding new vendors, but I'd like to grab the auto generated ID from the first table and put it in the second table so that they match. Is that even possible and if so, what would the code look like? Thanks. Using php/mysql.


 
insert into foo ( ... ) values ( ... )
;
insert into bar ( ... ) values ( last_insert_id(), ...)
;

r937.com | rudy.ca
 
Thanks. I didn't realize it was that simple. I guess what confused me about that function was i thought i'd have to put in the code what table it was to look to for the last insert. i guess mysql is smarter than I.

 
PHP also has a function in case you ever need it called: mysql_insert_id(); It returns the ID of the last inserted record.

_______________
_brian.
 
that php function calls last_insert_id(), but it is good to know what it is called in that app as it is quite popular.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top