Forum Moderators: coopster

Message Too Old, No Replies

INSERT into two tables passing same ID

getting first ID to insert same ID in second table

         

henry0

4:41 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello

I am trying to INSERT VALUES in two tables
(in one shot)
but would like passing the ID (auto incremented) from the fist one to the second one

how can I do it by modifying the following
that I borrowed here!
actually I think I have to find a way to find what is the a_table auto incremented ID
then passing it to the second table but how?

$query = "insert INTO a_table (id, val1, val2) VALUES ('', '$form_val1', '$form_val2');
insert INTO b_table (id, val3, val4) VALUES ('', '$form_val3', '$form_val4');";

but in b-table I need to pass the a_table ID value

thanks
regards

ukgimp

4:56 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LAST_INSERT_ID()

I found the above to work. You will need an auto increment for the second table plus a field for the ID from the first table.

So do the first insert then roll onto a new one. I think you will struggle if you try to do both at the same time. If you do know of a better way, please post it. :)

henry0

5:34 pm on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is there a way to trigger a form without "Submit"
if so will it be possible to first check for rows total #
then submit first form
check if rows# =rows +1
then auto submit the second