Insert Multiple Foreign Keys Simultaneously
<p>I have a form that gathers user input regarding a property they showed (a realtor showing to potential business leasees).</p>

<p>Upon submitting the form, I insert the data into three tables: <code>Showing</code>, <code>Business</code>, and <code>Contact</code>.  This form allows for the creation of new <code>Businesses</code> and new <code>Contacts</code>, while also creating a new <code>Showing</code> record.</p>

<p>I can insert the information into either my <code>Business</code> table and my <code>Contacts</code> table fine with an auto-incrementing <code>primary key</code>.</p>

<p>How do I insert the <code>primary key</code> from <code>Contacts</code> as a <code>foreign key</code> in <code>Business</code> when they are both submitted at the same time?</p>

<p>Should I have a values table which I select from for both the <code>primary key</code> and the <code>foreign key</code>? What are the best practices around this?</p>

<p>Additionally, I would like the insert the <code>primary keys</code> from both <code>Business</code> and <code>Contacts</code> as <code>foreign keys</code> in my <code>Showing</code> table.  I currently have a <code>BusinessID</code> as <code>foreign key</code> within <code>Contacts</code> but maybe <code>Contacts</code> should stand alone so that I can <code>Insert</code> it first and then just select for the subsequent <code>foreign keys</code>?</p>

<p>Finally I should note that for a database I am using <code>phpMyAdmin</code> and inserting via SQL within a <code>.php</code> page.</p>