title: How can I import Excel file in mysql?
body: <p>I have a code in which I can import .CSV file in my mysql. But I can not import Excel file. Some garbage values insert in my database while I import Excel file.</p>
  
  <pre><code>&lt;?php 
  if(isset($_POST["Import"]))
  {
  //First we need to make a connection with the database
  include("connection.php");
  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 city(city_id,city_name) values ('$emapData[0]','$emapData[1]')";
  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;
  &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>