title: How to Import Excel file into mysql Database from PHP
body: <p>Lets say,
  i want to import/upload excel file to mysql from PHP</p>
  
  <p>My HTML is like below</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" method="post" role="form"&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="exampleInputFile"&gt;File Upload&lt;/label&gt;
          &lt;input type="file" name="file" id="file" size="150"&gt;
          &lt;p class="help-block"&gt;Only Excel/CSV File Import.&lt;/p&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-default" name="Import" value="Import"&gt;Upload&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP code is like below</p>
  
  <pre><code>&lt;?php 
  if(isset($_POST["Import"]))
  {
      //First we need to make a connection with the database
      $host='localhost'; // Host Name.
      $db_user= 'root'; //User Name
      $db_password= '';
      $db= 'product_record'; // Database Name.
      $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
      mysql_select_db($db) or die (mysql_error());
      echo $filename=$_FILES["file"]["tmp_name"];
      if($_FILES["file"]["size"] &gt; 0)
      {
          $file = fopen($filename, "r");
          //$sql_data = "SELECT * FROM prod_list_1 ";
          while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
          {
              //print_r($emapData);
              //exit();
              $sql = "INSERT into prod_list_1(p_bench,p_name,p_price,p_reason) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]')";
              mysql_query($sql);
          }
          fclose($file);
          echo 'CSV File has been successfully Imported';
          header('Location: index.php');
      }
      else
          echo 'Invalid File:Please Upload CSV File';
  }
  ?&gt;
  </code></pre>
  
  <p>Excel file is like below</p>
  
  <p><img src="https://i.stack.imgur.com/e5iDu.png" alt="excel file picture"></p>
  
  <p>I want to import only the 2nd row values into my table. Please help me how can i solve it or give me any resource. I was able to upload the  excel file but it is  not correctly formatted. i want to upload 4 column in mysql's 4 column but it is uploading all 4 column in mysql's 1 column. am i missing something ?</p>