Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:20:20+00:00 2026-06-05T16:20:20+00:00

I am using below code to upload excel and INSERT in mysql in php

  • 0

I am using below code to upload excel and INSERT in mysql in php

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


        $this->load->library('Spreadsheet_Excel_Reader');

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

        $sql = "INSERT INTO $table (";

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

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

        return($sqlQuery );
    }

I am getting below error

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

I am using codeigniter php framework.

line number 154 -> $valuesSQL .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\"";

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:20:22+00:00Added an answer on June 5, 2026 at 4:20 pm

    It means either that row 3 doesn’t exist, or (more likely) that column “C” is an empty cell in one of the spreadsheet rows. You should test if isset($data->sheets[0][‘cells’][$i][$j]) before using it, and set an appropriate NULL value in your SQL if it doesn’t.

    if isset($data->sheets[0]['cells'][$i][$j]) {
        $valuesSQL .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\""; 
    } else {
        $valuesSQL .= 'NULL'; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the below code to fire an event when the upload queue
How do I browse to upload a file using Dojo? See the code below:
I'm using below code to check some form fields and render datatable table on
I am creating code to upload images in a folder using PHP, & before
I am using the code below to upload an image through ftp $sFile=$ftp_dir./.$image_name; $image=$database_row[image];//image
I have the code below which I am using to upload files to my
I'm using a code below to upload file (tens of MB) in streaming mode.
I am using the code below to upload a file. The files upload without
VS C# 2005 I am using the code below to upload a file to
VS C# 2005 I am using the code below to upload a file Async

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.