shahroznawaz / Import-Export-CSV-in-PHP

Simple script to import/export CSV files in PHP
https://www.cloudways.com/blog/import-export-csv-using-php-and-mysql/
10 stars 4 forks source link

import csv containing quotes #1

Open chipscompany opened 6 years ago

chipscompany commented 6 years ago

Hi, I use your script to import csv and it work great. Thanks. But it doesn't import the line that containing single quote (I didn't test with double quote). I tryed to change fgetcsv function and add PDO::quote() or mysqli::real_escape_string() but it's doesn't work.

SpaceTintin commented 5 years ago

I ran into the same issue. I used the line: $getData = str_replace("'","''",$getData); in functions.php. This replaces sinlge quotes with two single quotes which fixes the MySQL error and will keep the single quote in your data. I also added an additional getData statement to skip the first line so I don't have to remove headers.

functions.zip