[solved] submit two entries, figure out the foreign key?
Posted: Tue Jun 06, 2006 11:20 am
So here's my dilemma:
I have a site that needs three types of accounts: company, manager and employee.
I want a manager to be able to create a company account and manager account at the same time. So, after the single form is filled out, I need to make two entries...one to the company database, and one to the user database. The company table will have a primary key of comp_id but i need to insert that into the user table as a foreign key. Since my table auto increments the primary keys, how would i know what the key will be so that i can put it in the user table?
The only thing that i can think of right now is to enter the company info, then check for the max comp_id and use that as the foreign key. That doesnt sound like the best plan though...i think that would leave room for error.
I have a site that needs three types of accounts: company, manager and employee.
I want a manager to be able to create a company account and manager account at the same time. So, after the single form is filled out, I need to make two entries...one to the company database, and one to the user database. The company table will have a primary key of comp_id but i need to insert that into the user table as a foreign key. Since my table auto increments the primary keys, how would i know what the key will be so that i can put it in the user table?
The only thing that i can think of right now is to enter the company info, then check for the max comp_id and use that as the foreign key. That doesnt sound like the best plan though...i think that would leave room for error.