Hi
I have trying to upload data into my database from a .csv file, the code I have so far is

require_once ('../mysql_connect.php');//connect to the database

$filename = "../../Client.csv"; 
$fp = fopen($filename,"r"); 

while (!feof($fp)){ 

$data = fgetcsv($fp,100000); 

$ClientId = $data[0]; 
$ConcesRef = $data[1]; 
$CoName = $data[2]; 
$Addr1 = $data[3]; 
$Addr2 = $data[4]; 
$Addr3 = $data[5]; 
$Town = $data[6]; 
$County = $data[7]; 
$Postcode = $data[8]; 
$Phone = $data[9]; 
$Fax = $data[10]; 

$sql = "INSERT INTO tblClient (ClientId, ConcesRef, CoName, Addr1, Addr2, Addr3, Town, County, Postcode, Phone, Fax) 
VALUES ('$ClientId', '$ConcesRef', '$CoName', '$Addr1', '$Addr2', '$Addr3', '$Town', '$County', '$Postcode', '$Phone', '$Fax')";
$result = @mysql_query($sql) 
   or die(mysql_error());
   }

but when I run the script I get a very, very, very long repeating list of errors

Warning: fopen(../../Client.csv): failed to open stream: No such file or directory in /s/e/**os/upload/client_upload.php on line 8

Warning: feof(): supplied argument is not a valid stream resource in /s/e/**os/upload/client_upload.php on line 10

Warning: fgetcsv(): supplied argument is not a valid stream resource in /s/e/**os/upload/client_upload.php on line 12

with the line 10 and 12 errors repeated over and over again.

Where am I going wrong?

thanks in advance

    The csv file doesn't exist or is not visible to the script, you can tell this by the error message saying "No such file or directory" :rolleyes:
    Double check the file is there (remember that if this is an included file then you must work by the root file), also check the file permissions (ls -l on a *nix shell)

    HTH
    Bubble

      thanks for looking.
      The file Client.csv is definitely there, I have checked the root and made sure it is pointing to the right place.
      Is there any way i can check for reasons it isn't visible or the script cannot read it?
      thanks

        What operating system is your script running on? If you're on a *nix (unix, linux) then do you have shell access (telnet or ssh)? If you do then you need to go to the directory the file is located in and type ls -l this lists the files in "long" format meaning it will show you data about them. cut and paste the output, post it up here and I'll take a look at it.

          Write a Reply...