title: Inserting data of multiple fields into database table using FormData Class of JS?
body: <p>I need to insert data into MySql database table Using ajax and FormData Class.  I can easily  solve my this issue with declaring many variables for many <code>&lt;input&gt;</code> using jquery And then put these variables  for checks in if-else syntax. But what I need is to use <code>FormData</code> class of JavaScript and I distribute my code in 3 files:</p>
  
  <p><strong>action_project.php</strong></p>
  
  <pre><code>&lt;?php
    require_once("../config.php");
    include(CLASSES_PATH.DS.'project.php');
  
  $objProject = new Project();
  
  if(isset($_POST)) {
  
  $product            = isset($_POST['product'])?$_POST['product']:'';
  $customer           = isset($_POST['cutomer'])?$_POST['cutomer']:'';
  echo $objProject-&gt;AddProject($customer,$product);
  ?&gt;
  </code></pre>
  
  <p><strong>project.php</strong></p>
  
  <pre><code> class Project
   {
  private $mysqli_lib;
  
  function __construct()
  {
      global $obj_mysql;
      $this-&gt;mysqli_lib = $obj_mysql;
  }
  
  
  function AddProject($customer,$product)
  {
      $query = "INSERT INTO tbl_project_detail(customer,product) VALUES ('$customer','$product')";
       $response = $this-&gt;mysqli_lib-&gt;insert($query);
      return $response &gt; 0 ? "success" : "fail";
  }
  }
  </code></pre>
  
  <p><strong>project_view.php</strong> (for the sake of clarity i get rid of some html element tags)</p>
  
  <pre><code>  &lt;form method="post" class="form-horizontal" id="fieldsform" enctype="multipart/form-data" action="" style="clear:both"&gt;
      &lt;input type="text" class="form-control" name="product" value="product" 
     id="product"&gt;
   &lt;input type="text" class="form-control" name="customer" value="customer" 
     id="product"&gt;
    &lt;button type="submit" class="btn btn-primary" name="btnQuoSave" id 
      ="btnQuoSave"&gt;Save&lt;/button&gt;
    &lt;/form&gt;
        &lt;script type="text/javascript"&gt;
         $(document).ready(function() {
  
      $(document).on('click', '#btnQuoSave', function () {
  
          var formdata = new FormData($('#fieldsform')); //I need to figure out this line of code to work, i think.
  
          $.ajax({
              type: "POST",
              url: "../includes/ajax/action_project.php",
              async: true,
              contentType: false,
              processData: false,
              cache: false,
              data: formdata,
  
              success: function(data){
              data = data.trim();
              //console.log(data);
              //alert(data);
  
              if(data == 'success'){
               alert('sucess');
  
              }else if(data == 'fail'){
                  alert('fail');
                }
  
             }
  
      });
  
       });  
    });
  </code></pre>
  
  <p></p>
  
  <p><strong>So My Questing is How should i insert data into MySql database table Using ajax and FormData Class?</strong></p>