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 9138939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:19:19+00:00 2026-06-17T09:19:19+00:00

I am using the PHP code below to make bulk insert into database table

  • 0

I am using the PHP code below to make bulk insert into database table in SQL Server. I already have a table called ShopifyItem (with 25 columns) but when I use this code I got

Undefined offset: 24

error message and in Item table I only see
(26 row(s) inserted properly) even the csv file have more than 1,000 in row.

Can anyone tell me what’s wrong?

PHP code:

$server = "**\**,1433";
$connectionInfo = array( "Database"=>"**", "UID"=>"**", "PWD"=>"**" );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true));
}
$file_handle = fopen("Table.csv", "r");

while (!feof($file_handle) ) {

$line_of_text = fgetcsv($file_handle, 1024);

 $tsql = "INSERT INTO Item (Handle, Title, [Body(HTML)], Vendor, [Type], Tags, [Option1 Name],[Option1 Value], [Option2 Name], [Option2 Value], [Option3 Name], [Option3 Value], [Variant SKU], [Variant Grams], [Variant Inventory Tracker],[Variant Inventory Qty], [Variant Inventory Policy], [Variant Fulfillment Service], [Variant Price], [Variant Compare At Price], [Variant Requires Shipping], [Variant Taxable], [Image Src], HQID, WebPrice)
         VALUES ('$line_of_text[0]','$line_of_text[1]', '$line_of_text[2]', '$line_of_text[3]', '$line_of_text[4]', '$line_of_text[5]', '$line_of_text[6]', '$line_of_text[7]', '$line_of_text[8]', '$line_of_text[9]', '$line_of_text[10]', '$line_of_text[11]', '$line_of_text[12]', '$line_of_text[13]', '$line_of_text[14]', '$line_of_text[15]', '$line_of_text[16]', '$line_of_text[17]', '$line_of_text[18]', '$line_of_text[19]', '$line_of_text[20]', '$line_of_text[21]', '$line_of_text[22]', '$line_of_text[23]', '$line_of_text[24]' )"; 

if( sqlsrv_query( $conn, $tsql))
{
      echo "Statement executed.\n";
} 
else
{
      echo "Error in statement execution.\n";
      die( print_r( sqlsrv_errors(), true));
}

} 
  • 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-17T09:19:20+00:00Added an answer on June 17, 2026 at 9:19 am

    If there are no problems with your csv file, the likely candidate is this line:

    $line_of_text = fgetcsv($file_handle, 1024);
    

    You are limiting the data read for each line to 1024 bytes. If the line is longer than this, it will be truncated, and possibly give you this error of missing elements. You can change the buffer size, like this, if you know the maximum line length:

    $line_of_text = fgetcsv($file_handle, 2048);
    

    Or even try it like this to see if this is the cause of your problem:

    $line_of_text = fgetcsv($file_handle);
    

    This will just run a little slower, but will not limit your line length.

    If this does not work, then it would be useful if you could post the csv data lines 20-30.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using below code to upload excel and INSERT in mysql in php
I am using the below PHP code with Google's Translate API and I have
I have written below code to make an ajax call using jquery: $.ajax({ url:
I use PHP code below for login without using database. It redirects to home.php
I am using php code to query to a database and the results will
I'm using the code below to make a box appear when certain text is
I'm using the code below to make sure only confirmed users (confirmed is 1,
I am using this code below: <div class=feat-product> <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('feat_products')->toHtml() ; ?> </div>
I'm trying to create a simple database table using the PHP MySQL query Create
I am using the code below to do pagination on a table (please do

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.