Jump to content

Archived

This topic is now archived and is closed to further replies.

sandhya

[SOLVED] Problem with uploading csv file to the mysql database

Recommended Posts

Hi all, please give me a solution for this. I have converted an Excel file into .csv file. And browsed from the form with the form field named 'csvfile'. And i'm trying to upload the form using the following code.

 

$file1=$_FILES['csvfile']['name'];

$lines = file($file1);

foreach ($lines as $line) {

  $cols = explode(';', $line);

    mysql_query("INSERT INTO aop_class (catid, orgname, address, city, country, phone, description) VALUES(".trim($cols[0]).",'".trim($cols[1])."','".trim($cols[2])."','".trim($cols[3])."','".trim($cols[4])."','".trim($cols[5])."','".trim($cols[6])."')") or

    die(mysql_error());

 

But, after execution i'm getting the following wornings

 

Warning: file(): Unable to access class1.csv in /home/sphoor21/public_html/mitrahelp/admin/classified.php on line 165

 

Warning: file(class1.csv): failed to open stream: Permission denied in /home/sphoor21/public_html/mitrahelp/admin/classified.php on line 165

 

So, Please tell me what is happening her. How can I upload a csv file to the database. Thanks in advance.

Share this post


Link to post
Share on other sites

DO you have acess to phpMyAdmin?

 

It will give you an easy way to import your CSV data.

Share this post


Link to post
Share on other sites

Yes i"ve the access to PhpMyAdmin. But I am developing the admin tool for the clients. Through that they can easily upload the data to the database. what is the error in that code?

Share this post


Link to post
Share on other sites

Consider giving them limited access to phpMyAdmin then...

 

It uses LOAD DATA INFILE method, so it is much faster, than INSERTing row by row.

 

If you want to stick with your own script, perhaps you should also consider uploading csv first, and then using LOAD DATA INFILE.

Share this post


Link to post
Share on other sites

Basically it's not possible to give them the access to php MyAdmin in this case. So, Please give me a solution.

Share this post


Link to post
Share on other sites

Basically it's not possible to give them the access to php MyAdmin in this case. So, Please give me a solution.

Michl has offered you a solution

If you want to stick with your own script, perhaps you should also consider uploading csv first, and then using LOAD DATA INFILE.

Share this post


Link to post
Share on other sites

Thank you very much. code worked properly after uploading the csv file to the server. thank u very much.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.