Welcome Guest, Not a member yet? Register   Sign In
CSV upload, once uploaded to a temp folder overwrite the existing database
#24

[eluser]the_unforgiven[/eluser]
I changed my original to incorporate what you said:

Code:
$csv_upload = array('upload_data' => $this->upload->data());
  
   //Get the data from some web resource in csv format
     $data = file_get_contents("http://localhost/sussex/assets/uploads/wc_program.csv");
  
   //Explode the csv into an array of lines
   $lines = explode(",", $data);
    
   $file_handle = fopen("http://localhost/sussex/assets/uploads/wc_program.csv", "r");

   $insert_str = 'INSERT INTO wc_program_temp (JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish) VALUES '."\n";

   while (($line_of_data = fgetcsv($file_handle, 1000, ",")) !== FALSE)
   {

   $insert_str .= '("'
         // Implode the array and fix pesky apostrophes.
         .strtr(implode('","', $line_of_data), array("'" => "''", "-" => " ", "/" => " ", "(" => " ", ")" => " "))
         .'")'."\n";

        //mysql_query($line_import_query) or die(mysql_error());
         if ($this->db->query($insert_str))
     {
        $this->load->view('program/success');
       //echo '[removed]
        //  alert("Document successfully uploaded and saved to the database.");
        //  location = "program/index";
     //[removed]';
     }
     else {
       echo '[removed]
          alert("Sorry! Something went wrong please proceed to try again.");
          location = "program/upload";
     [removed]';
     }

       }
But still getting sql syntax
Quote:Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("912049","Coastal","Yapton","Micro","Micro Asphalt Surfacing","TBC","No Positiv' at line 3

INSERT INTO wc_program_temp (JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish) VALUES ("911847","Coastal","Yapton","Micro","Micro Asphalt Surfacing","TBC","No Positive Traffic Management","Canal Road added PMI 16 07 12 ","2 days","0000 00 00","0000 00 00") ("912049","Coastal","Yapton","Micro","Micro Asphalt Surfacing","TBC","No Positive Traffic Management","Blenheim Road added PMI 16 07 12 ","2 days","0000 00 00","0000 00 00")

Filename: C:\xampp\htdocs\sussex\system\database\DB_driver.php

Line Number: 330

As you can see from
Code:
.strtr(implode('","', $line_of_data), array("'" => "''", "-" => " ", "/" => " ", "(" => " ", ")" => " "))
         .'")'."\n";
i have stripped everything out and just put spaces in, but still the same error.


Messages In This Thread
CSV upload, once uploaded to a temp folder overwrite the existing database - by El Forum - 03-24-2013, 12:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB