...

View Full Version : any way to insert data into two tables at the same time?



mhunt
01-23-2007, 04:37 PM
what I have is a table called `order` and a table called `lmcharge`.
a person inputs data from a form and i need to take the data from both and some goes into one table, some goes into another
here is an example:
order values:
student_id, class_id, order_type, date, status
//student_id, class_id, order_type will be from the form

lmcharge values:
student_id, order_id, lm_number
//student_id, and lm_number will also be from the form but order_id will have to be from the order table

anyone have a clue?

guelphdad
01-23-2007, 06:47 PM
make the order_id in the orders table an auto increment column and then use last_insert_id() to retrieve the value to insert into the second table. You would do two inserts and should wrap them in a transaction.

See the link in my signature to view an article on using last_insert_id.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum