title: How to loop through an array of dynamic form inputs and insert them into more than one table?
body: <p>I have a master form for inserting recipes into a database. Most of the form is working except for being able to insert more than one ingredient into the database. </p>
  
  <p>I think I need an array to hold the ingredient inputs (ingredient_name, amount, measurement type) and then to somehow loop through that array as many times as it has been filled out (user can click an 'add new ingredient' button and jquery adds a new set of inputs). I could probably figure this out on my own as this has been asked before, but...</p>
  
  <p><strong>...the real problem I'm having is that the 'ingredient_name' input needs to be inserted into one table (ingredients) and the 'amount' and 'measurement type' inputs need to be inserted into another table (ingredientLists). I have no idea how to do this.</strong></p>
  
  <pre><code>&lt;input type="text" name="ingredient_name" value="" /&gt;
  &lt;input type="text" name="amount" value="" /&gt;
  &lt;select name="measurement_ID" value=""&gt; 
     &lt;option value="14" &gt;n/a&lt;/option&gt; 
     &lt;option value="1"  &gt;teaspoon&lt;/option&gt; 
     &lt;option value="2"  &gt;tablespoon&lt;/option&gt; 
     &lt;option value="3"  &gt;fluid ounce&lt;/option&gt; 
     &lt;option value="4"  &gt;cup&lt;/option&gt; 
     &lt;option value="5"  &gt;pint&lt;/option&gt; 
     &lt;option value="6"  &gt;quart&lt;/option&gt; 
     &lt;option value="7"  &gt;pound&lt;/option&gt; 
     &lt;option value="8"  &gt;ounce&lt;/option&gt; 
     &lt;option value="9"  &gt;milligram&lt;/option&gt; 
     &lt;option value="10" &gt;gram&lt;/option&gt; 
     &lt;option value="11" &gt;millimeter&lt;/option&gt; 
     &lt;option value="12" &gt;centimeter&lt;/option&gt; 
     &lt;option value="13" &gt;inch&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I'm not sure if I can even process it correctly using the form set-up I have now.</p>
  
  <p>This is what I have processing the ingredient inputs so far (this set-up only allows the first ingredient to be entered into the database).</p>
  
  <pre><code>                $recipe_id = $pdo-&gt;lastInsertId('recipe_ID');
  
                  //inputs inserted into ingredient table
                  $query2 = $pdo-&gt;prepare('INSERT INTO ingredients (ingredient_name) VALUES (?)');
                  $query2-&gt;bindValue(1, $ingname);
  
                  $query2-&gt;execute();
  
                  $ingredient_id = $pdo-&gt;lastInsertId('ingredient_ID');
  
                  //inputs inserted into ingredient list table
                  $query3 = $pdo-&gt;prepare('INSERT INTO ingredientLists (recipe_ID, ingredient_ID, amount, measurement_ID) VALUES (?,?,?,?)');
                  $query3-&gt;bindValue(1, $recipe_id);
                  $query3-&gt;bindValue(2, $ingredient_id);
                  $query3-&gt;bindValue(3, $amount);
                  $query3-&gt;bindValue(4, $measure);
  
                  $query3-&gt;execute();
  </code></pre>