With the code snippet given in the following post
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.

Recommended Answers

All 2 Replies

Member Avatar

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());

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.