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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:24:45+00:00 2026-06-13T19:24:45+00:00

I have a script that extracts several rows of data from an external file,

  • 0

I have a script that extracts several rows of data from an external file, I then need to upload each of these rows to a database. I put a query inside my loop but it does nothing. even with error reporting turned on I get nothing. I check the database but nothing is being uploaded.

What is the correct way to do this?
Thanks in advance!

My Code:

$size = $_FILES['file']['size'];
$filename = $_FILES['file']['tmp_name']; 
$max_filesize = 100000;
  if($size > $max_filesize) //check file size
  die('File is too large');

if(file_exists($filename)){
$fp = fopen($filename, "r");
$str = fread($fp, filesize($filename)); //file text stored in variable
$br = "\n";          //search for new row
$rows = substr_count($str,$br);  //number of rows
echo "Rows: ". $rows."<br />"; 
$row = explode( "\n",$str);

 $x=0;
while($x<=$rows)
  {
  $field = $row[$x]; 
  $exp = explode("|",$field); 

    $case_number = $exp[1];
    $unknown1 = $exp[2];
    $chapter = $exp[3];
    $filed = $exp[8];
    //tons more variables, removed for readability

   $addrow = mysql_query("INSERT INTO records (case_number, wild1, chapter, filed) VALUES('".$case_number."', '".$unknown1."', '".$chapter."', '".$filed."')");
    if($addrow)  
    {  
    echo "<p style=\"font-weight:bold\">Row ".$x." uploaded</p>";   
    }else{
die(mysql_error());
}  

  $x++;
  }
fclose($fp); 
 }
  • 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-13T19:24:46+00:00Added an answer on June 13, 2026 at 7:24 pm

    You have mentioned the error Duplicate entry for key 'PRIMARY' so you cannot have a duplicate value in the column which is set to PRIMARY.

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

Sidebar

Related Questions

I have some script that extracts some text from a table and dumps it
In a script I have several functions that need to break down an SVN
I have a data flow task that extracts data from one database and inserts
I have a script that reads in a large data file 3GB I don't
I have script that reads remote file content and writes it to local server.
I have a script that submits data via an ajax POST. It is called
I have a script that reads a list of addresses from a table and
I'm writing a script that will grab several files and then copy them into
I'm learning SPARC assembly and I have to create a script that extracts a
When I do translation for web apps, usually I have a script that extracts

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.