title: How to pass 2 array in foreach using $_POST
body: <p>I am trying to insert dynamic form filed values into the database. To insert these values in database,I am trying to apply foreach loop in MySQL query
  The code goes like this:</p>
  
  <pre><code>if (isset($_POST['submit_val'])) {
  if  ($_POST['elements'],$_POST['quanity']){
  foreach($_POST['elements'] as $elements){
      foreach($_POST['quantity'] as $quantity){
      $sql[] = "INSERT INTO create_campaign (elements, quantity) VALUES ('{$elements}','{$quantity}')";
  }
  }
  
     foreach($sql as $query){
    mysql_query($query);
  }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>&lt;div class="row col-md-12" ng-app="angularjs-starter" ng-controller="MainCtrl"&gt;
                                                      &lt;fieldset  data-ng-repeat="choice in choices" name="records"&gt;
                                                          &lt;label for="inputPassword3" class="col-md-1 control-label"&gt;Elements&lt;/label&gt;
                                                          &lt;div class="form-group col-md-3 "&gt;
                                                              &lt;input type="text" placeholder="Campaign Name" ng-model="choice.name" class="form-control c-square c-theme input-lg" name="elements[]" multiple&gt; 
                                                          &lt;/div&gt;
                                                          &lt;label for="inputPassword3" class="col-md-1 control-label"&gt;Quantity&lt;/label&gt;
                                                          &lt;div class="form-group col-md-3" &gt;
                                                             &lt;select class="form-control  c-square c-border-2px c-theme"  name="quantity[]"&gt;
                                                               &lt;option value="1"&gt;100&lt;/option&gt;
                                                               &lt;option value="2"&gt;200&lt;/option&gt;
                                                               &lt;option value="3"&gt;300&lt;/option&gt;
                                                               &lt;option value="4"&gt;400&lt;/option&gt;
  
                                                              &lt;/select&gt;
                                                          &lt;/div&gt;
  
                                                       &lt;button type="button" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" ng-click="addNewChoice()" id="add_field"&gt;add&lt;/button&gt;
                                                       &lt;button   ng-show="$last" ng-click="removeChoice()" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" &gt;Remove&lt;/button&gt;
                                                       &lt;/fieldset&gt;  
                                                  &lt;/div&gt;   
                                             &lt;/div&gt;
                                          &lt;/div&gt;
  
                                        &lt;div class="form-group"&gt;
                                              &lt;input type="text" placeholder="Description" class="form-control c-square c-theme input-lg" name="description"&gt;
                                        &lt;/div&gt;
                                          &lt;input class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square" value="Submit" type="submit" name="submit_val"&gt;
  </code></pre>
  
  <p>It's giving error and insertion of the database is not happening, what do I do?</p>