tags:

views:

34

answers:

3

I had two table

restaurant_orders with fields order_id, restaurant_id, tot_amt   where order_id is (Autoinc, primary)
order_menus with fields order_id, menu_id, quantity

when the user clicks submit button the record will be stored at restaurant_orders with the field order_id is automatically generated.

Also a record will be stored at order_menus table. Both will happen at same time

What i want is the order_id stored at both the table should be same. How is it possible. plz help

+1  A: 

use mysql_insert_id to get the first id then pass it as order_id to the second table.

Iznogood
+1  A: 

I don't fully understand your question but you can get the last insert id using mysql_insert_id() and you can use that in your order_menus table.

Sarfraz
A: 

Here's a nice article that describes how to do what you want:

http://www.terminally-incoherent.com/blog/2006/12/04/mysql-how-to-get-the-key-of-last-inerted-row-in-php/

You're going to have to make 2 INSERTs regardless of what you do because that's just how inserting works. From that article you can do it pure mySQL:

INSERT INTO tab1 (name) VALUES ('some value')
INSERT INTO tab2 (value, tab1_id) VALUES ('another value', LAST_INSERT_ID())

or with php:

$last_inserted_row = mysql_insert_id($dblink)
clumsyfingers