I'm trying to import a csv file to my database. It's working but the problem is I have a column, namely "address1" and "address2" which may have commas. Example is:
194 Chavez compound, Something City
What's happening is194 Chavez compound is in the "address1" and Something City is in "address2". The whole address should be in "address1" only.
This is my code on importing in my database:
do {
if ($data[0]) {
mysql_query("INSERT INTO awb (recNAME, company, address1, address2, city, province, postalCODE, contactNO, email, commodity, type, weight, length, width, height, decVAL, specINSTRUC, shipREF, payMETHOD, packNO, trackNO) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."',
'".addslashes($data[5])."',
'".addslashes($data[6])."',
'".addslashes($data[7])."',
'".addslashes($data[8])."',
'".addslashes($data[9])."',
'".addslashes($data[10])."',
'".addslashes($data[11])."',
'".addslashes($data[12])."',
'".addslashes($data[13])."',
'".addslashes($data[14])."',
'".addslashes($data[15])."',
'".addslashes($data[16])."',
'".addslashes($data[17])."',
'".addslashes($data[18])."',
'".addslashes($data[19])."',
'".addslashes($data[20])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
LOAD DATA INFILEor mysqlimport?"characters) or such delimiters within fields are not escaped in some way (e.g. with backslash\characters), how can any parser possibly know whether a given delimiter is part of a field or not?,. A parser is a program which reads a file and understands how the data within it should be divided up.mysql_real_escape_string()instead ofaddslashes(). However, I would recommend that you instead focus on gettingLOAD DATAor mysqlimport to work for you.