Undefined offset: 3 error excel file upload and INSERT
<p>I am using below code to upload excel and INSERT in mysql in php</p>

<pre><code>public function read_file($table = 'users', $filename = 'test.xls') {


        $this-&gt;load-&gt;library('Spreadsheet_Excel_Reader');

        //$data = new Spreadsheet_Excel_Reader($pathToFile);
        $data = new Spreadsheet_Excel_Reader();
         $data-&gt;read($filename);

        $sql = "INSERT INTO $table (";

        for($index = 1;$index &lt;= $data-&gt;sheets[0]['numCols']; $index++){
            $sql.= strtolower($data-&gt;sheets[0]['cells'][1][$index]) . ", ";
        }
        $valuesSQL = '';
        $sql = rtrim($sql, ", ")." ) VALUES ( ";
        for ($i = 2; $i &lt;= $data-&gt;sheets[0]['numRows']; $i++) {

            for ($j = 1; $j &lt;= $data-&gt;sheets[0]['numCols']; $j++) {
                $valuesSQL .= "\"" . $data-&gt;sheets[0]['cells'][$i][$j] . "\"";
                if($j!=$data-&gt;sheets[0]['numCols']){
                        $valuesSQL .= ",";
                }
            }
            if($i!=$data-&gt;sheets[0]['numRows']){
                $valuesSQL .= "),(";
            }else{
                $valuesSQL .= ")";
            }
        }
        $sqlQuery = $sql . rtrim($valuesSQL);

        return($sqlQuery );
    }
</code></pre>

<p>I am getting below error</p>

<pre><code>A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 3

Filename: controllers/userInfo.php

Line Number: 154
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 3

Filename: controllers/userInfo.php

Line Number: 154
</code></pre>

<p>I am using codeigniter php framework.</p>

<p>line number 154 -> <code>$valuesSQL .= "\"" . $data-&gt;sheets[0]['cells'][$i][$j] . "\"";</code></p>
