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

  • Home
  • SEARCH
  • 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 3232496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:10:04+00:00 2026-05-17T17:10:04+00:00

I am trying to upload a text file with more than one record but

  • 0

I am trying to upload a text file with more than one record but I keep getting a syntax() error.
The implemented logic works fine if there is only one record in the file.
Could the problem be that I am echoing multiple records in my foreach loop?

Description:

Ext JS interface where the user browses for a file. Once file is selected it is then uploaded to the server and parsed in PHP. The parsed process is called processFile
which is called by the js file.

What I have noticed

  1. The implemented logic works fine if there is only one record in the file.
  2. The json format is correct.
  3. If the file contains 3 records a fourth BLANK record is still read.

Herewith the PHP code:

<?php

$action = $_REQUEST['action'];
if ($action == 'uploadFile') {
  $fileName = $_FILES['file']['tmp_name'];
  $fileContent = file_get_contents($fileName);
  $fileInfo = parseFile($fileContent); //custom formatting 
    echo wrap_answer(array(
    'originalFile' => $fileContent,    
    'fileInfo' => $fileInfo,
    'success' => true
    ));  
}

if ($action == 'processFile') {
  $fileContent = $_REQUEST['file'];
  $fileInfo = parseFile($fileContent);  

  foreach($fileInfo['lines'] as $line) {        
    $input = array(
            'id' => $line['id'],
            'name' => $line['name']);              
    //custom function to insert records from file into clients table
    //function returns the inserted records ID  
    $insert_id = handler_Insert('clients',$input);    

    $success = ($insert_id == null || $insert_id == 0)?false:true;
    echo json_encode(array(
    'success' => $success)
    );    
    //NOTE:Processing records 1 by 1 and echoing the result
    //     Could this be the error? Any suggestions to better
    //     handle this process?
  }
}

Any help,suggesstions etc much appreciated!
Thanks

  • 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-05-17T17:10:05+00:00Added an answer on May 17, 2026 at 5:10 pm

    SOLVED

    I had to rewrite my code to return only ONE json string with multiple records
    like this:

     //new variable to hold all array elements
        $rows = array();
        //In the foreach loop push the array item on $rows
        array_push($rows,array(
          'success' => $success,
          'record' => $input));    
    
        } //end of foreach loop
          echo json_encode(array(
          'id' => 'clients',
          'rows' => $rows));
       }//end of processFile function
    

    Then in my js file all I had to do was loop through the result using
    Ext.each like this:

    loadClient:function(result){
          var records = result.rows; //rows[0]{id,name},rows[1]      
          console.log(records);
          Ext.each(records,this.processKey,this);
        },
    processKey:function(item,itemIndex){
          if(item.success){
             alert('Record inserted!');
          }
          else{
             alert('Failed to insert record');
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.