title: Post using for each php
body: <p>I have a form with more than 1 input, it has a button to duplicate the form, while saving the data i am using foreach but its not working, help anyone.</p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST['submit_button'])) {
      // Connecting to database
      $conn = mysql_connect('localhost', 'root', '');
      if (!$conn || !@mysql_SELECT_db('finalyearproject')) {
          echo("Can NOT connect to server");
          exit;
      }
  
      // Values to insert
      $functionID = 0;
      $functionName = $_POST ["functionName"];
      $functionDependency = $_POST["functionDependency"];
      $projectID = $_SESSION["projectID"];
  
  
      // insertion to user_details table
      foreach ($functionID as $eachInput) {
  
          $sql = "INSERT INTO function (functionID, functionName,functionDependency,projectID) 
              VALUES ('$eachInput', '$functionName', '$functionDependency','$projectID')";
          if ($conn-&gt;query($sql) === TRUE) {
  
              header("Location: du.php?message=success");
          } else {
              echo "Error updating record: " . $conn-&gt;error;
          }
      }
  }
  ?&gt;
  </code></pre>
  
  <p>this is my html form, hope it would help you people to fine my error </p>
  
  <pre><code>     &lt;form action="analystCreateFunction.php" method="post" id="sign-up_area" role="form"&gt;
            &lt;div id="dynamicInput"&gt;
        &lt;div class="box box-default"&gt;
          &lt;div class="box-header with-border"&gt;
           &lt;p&gt;Create Function&lt;/p&gt;
  
          &lt;/div&gt;&lt;!-- /.box-header --&gt;
          &lt;div class="box-body"&gt;
            &lt;div class="row"&gt;
              &lt;div class="col-md-6"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="label_fn control-label" for="first_name"&gt;Function Name:&lt;/label&gt;
                  &lt;input id="first_name" name="functionName[]" type="text" placeholder="" class="input_fn form-control" required=""&gt;
              &lt;/div&gt;
  
              &lt;/div&gt;&lt;!-- /.col --&gt;
              &lt;div class="col-md-6"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label class="label_fn control-label" for="first_name"&gt;Function Dependency:&lt;/label&gt;
                  &lt;input id="first_name" name="functionDependency[]" type="text" placeholder="" class="input_fn form-control" required=""&gt;
              &lt;/div&gt;
  
              &lt;/div&gt;&lt;!-- /.col --&gt;
            &lt;/div&gt;&lt;!-- /.row --&gt;
          &lt;/div&gt;&lt;!-- /.box-body --&gt;
        &lt;/div&gt;&lt;!-- /.box --&gt;
        &lt;/div&gt;
  
   &lt;input type="button" class="btn btn-primary" value="Add another Function" onClick="addInput('dynamicInput');"&gt;
        &lt;button id="submit_button" name="submit_button" class="btn btn-primary"&gt;Submit&lt;/button&gt;
        &lt;/form&gt;
  </code></pre>