title: i want to import excel file into mysql in codeigniter?
body: <p>iwant to import excel file into mysql.i created a table in db ,name of the table is statement.please guide me</p>
  
  <p>mycontroller</p>
  
  <pre><code> function my_test()
          {
                  $table = 'statement';
          $filename ='expense.xls';
  
        $pathToFile = './uploads/' . $filename;
  
      //           print_r($pathToFile);die;
                 $valuesSql="";
                  $this-&gt;load-&gt;library('Excel_Reader');
                  $data = new Excel_Reader($pathToFile);
                  $sql = "INSERT INTO $table (";
                  for($index = 1;$index &lt;= $data-&gt;sheets[0]['numCols']; $index++){
                  $sql.= strtolower($data-&gt;sheets[0]['cells'][1][$index]) . ", ";
                  }
  
                  $sql = rtrim($sql, ", ")." ) VALUES ( ";
                  for ($i = 2; $i &lt;= $data-&gt;sheets[0]['numRows']; $i++) {
                  $valuesSQL = '';
                  for ($j = 1; $j &lt;= $data-&gt;sheets[0]['numCols']; $j++) {
                  $valuesSql .= "\"" . $data-&gt;sheets[0]['cells'][$i][$j] . "\", ";
                  }
                  echo $sql . rtrim($valuesSql, ", ")." ) &lt;br&gt;";
                  }                                           // add this line
  
  
          }                        
  
  
  
      }
  </code></pre>
  
  <p>my view page is</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Upload Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php // echo $error;?&gt;
  
  &lt;?php echo form_open_multipart('Upload_c/my_test');?&gt;
  
  &lt;input type="file" name="file_name" size="20" /&gt;
  
  &lt;br /&gt;&lt;br /&gt;
  
  &lt;input type="submit" name="up" value="upload" /&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>when i click the upload button in view page,it is showing error like this</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined offset: 0
  
  Filename: controllers/Upload_c.php
  
  Line Number: 33
  
  A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined offset: 0
  
  Filename: controllers/Upload_c.php
  
  Line Number: 38
  </code></pre>