The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I then need to insert everything into the ORDER table, and, get the orderid returned to me, so that I can then insert it into the JOB table. How would I go about doing this? I'm using PHP / MySQL, and I only have primary key's setup.
I did think about just returning the most recently added ID from the order table, but then realized, you could have somebody adding to that table inbetween the SQL statements taking place (it's unlikely, and impossible in my situation, but I just want to know how to do it the correct way!).

The ideal way would be to use a transaction. If the first fails don't insert the other. If the second fails don't commit the transaction. However, depending upon your table engine types that may not be viable. The other option would be to insert the first. If that query is a success insert the next. If that query fails then use the last insert id of the previous query to delete the first insert. Again, depending on the type adaptor your using the function or method to return the last insert id will vary. That is essentially the way you would retrieve the primary key of the most recent inserted item. The exact function or method name to retrieve the last insert id varies slightly between database adaptors.