title: How can I import data from an XLS file to MySQL?
body: <p>As I am trying to import MS Excel data to MySQL data base 
  using the following code:</p>
  
  <pre><code>&lt;?php  
      $db_username="root"; //database user name
      $db_password="";//database password
      $db_database="hr_mysql"; //database name
      $db_host="localhost";
  
  
      mysql_connect($db_host,$db_username,$db_password);
      @mysql_select_db($db_database) or die( "Unable to connect to database.");
  
      $handle = fopen("UploadIt.xls", "r"); //test.xls excel file name
      if ($handle)
      {
          $array = explode("\n", fread($handle, filesize("UploadIt.xls")));
      }
  
      $total_array = count($array);
      $i = 0;
      $Leave_Type_Id1="LTY001";
      $Leave_Type_Id2="LTY002";
  
      while($i &lt; $total_array)
      {
      $data = explode(",", $array[$i]);    
      //$sql = "insert into test values ('$data[0]','$data[1]')";
      $sql = "update `hs_hr_employee_leave_quota` set `no_of_days_allotted`= {$data[0]} WHERE `employee_id`= {$data[0]} and `leave_type_id`= '{$Leave_Type_Id1}'";        
      $result = mysql_query($sql);
      $sql = "update `hs_hr_employee_leave_quota` set `no_of_days_allotted`= {$data[2]} WHERE `employee_id`= {$data[0]} and `leave_type_id`= '{$Leave_Type_Id2}'";        
      $result = mysql_query($sql);
      $i++;
      }
      if($result==false)
              echo "Not succed";  
      else 
      {
          echo "completed";   
      }
  
  ?&gt;
  </code></pre>
  
  <p>And my .xls sheet is:</p>
  
  <p>But I am getting error saying</p>
  
  <p>htdocs\Verify\XL_To_DBTable.php line 28 - Undefined offset:  2</p>
  
  <h2>|1|2|5|</h2>
  
  <h2>|2|3|5|</h2>
  
  <h2>|3|3|4|</h2>
  
  <h2>|4|3|9|</h2>
  
  <h2>|5|4|1|</h2>
  
  <p>(Assume above one as xls sheet only)</p>