Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2007, 03:37 PM   PM User | #1
mhunt
Regular Coder

 
Join Date: Mar 2005
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
mhunt is an unknown quantity at this point
any way to insert data into two tables at the same time?

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?
mhunt is offline   Reply With Quote
Old 01-23-2007, 05:47 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
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.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:46 PM.


Advertisement
Log in to turn off these ads.