I did a quick search on this and didn't find anything. I've been trying for several days to finish a script I'm writing to dump a csv file to an sql database using a php submit form, and have come across a slight snag.
In several of the csv fields i need to upload, there exists a single quote ( ' ). ex: 203 Martha's Way
This causes sql to stop the query at that spot and report an error. Here is the relevant code, I'd appreciate any help anyone can lend.
<?
if(isset($_POST['upload'])) {
$filename = ($_FILES['userfile']['tmp_name']);
$handle = fopen($filename, 'r');
$row = 1;
while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE) {
mysql_query ("
INSERT INTO cc_test (
lastname,
firstname,
oldaddress,
oldcitystate,
oldzip,
phone,
newaddress,
newcitystate,
newzip,
office)
VALUES (
'" . $data[0] . "',
'" . $data[1] . "',
'" . $data[2] . "',
'" . $data[3] . "',
'" . $data[4] . "',
'" . $data[5] . "',
'" . $data[6] . "',
'" . $data[7] . "',
'" . $data[8] . "',
'" . $data[10] . "'
)
")
or die(mysql_error());
}
fclose($handle);
}
?>
Kudos.