title: Inserting data into multiple tables PHP MySQL
body: <p>I have a basic data structure for storing recipes. It consists of three tables as below:</p>
  
  <p><strong>Table 1 - Recipes (recipe_id, recipe_name)</strong></p>
  
  <p><strong>Table 2 - Ingredients (ingredient_id, ingredient_name)</strong></p>
  
  <p><strong>Table 3 - Recipe_Ingredients (recipe_id, ingredient_id)</strong></p>
  
  <p>I have come across a problem when adding a new recipe and would like to know the best practice for inserting. </p>
  
  <p>Currently, on submitting the form I insert into the <strong>Recipes</strong> table, the recipe_id is auto generated. I then insert into the <strong>Ingredients</strong> table, again the ingredient_id is auto generated. The third step on submit is to then insert into the <strong>Recipe_Ingredients</strong> table, but how do I get the values of the recipe and ingredient ids that have just been created in order to insert them into the <strong>Recipe_Ingredients</strong> table?</p>
  
  <p>I currently have separate PHP functions to insert into the <strong>Recipes</strong> and <strong>Ingredients</strong> tables.</p>