We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,047 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to import CSV file into phpmyadmin using PHP?

Hi
With the code snippet given in the following post
http://www.daniweb.com/web-development/php/threads/126361/csv-file-uploading-into-a-mysql-database
I am able to import csv data into phpmyadmin. However, I am getting an error if csv data contains a text with apostrophe (‘) symbol (e.g. my book’s name is abc).
Appriciate any suggestions to resolve this error.
Thank you.

2
Contributors
2
Replies
5 Days
Discussion Span
10 Months Ago
Last Updated
3
Views
Question
Answered
nikki05
Newbie Poster
20 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Likely to be a problem with SQL rather than reading the csv.
You may need to use mysql_real_escape_string() on data items - you could use array_map for this. I'm assuming you have a variation on the following:

     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
     {
         //this line added
         $data = array_map("mysql_real_escape_string",$data);

         $sql = "INSERT into users(name,lastname,email) values('$data[0]','$data[1]','$data[2]')";
         mysql_query($sql) or die(mysql_error());
     }
diafol
Keep Smiling
Moderator
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57

Hi Diafol,
Thank you very much for your code. It helped me to solve my problem.

nikki05
Newbie Poster
20 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 10 Months Ago by diafol

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0563 seconds using 2.64MB