Hi All,
I am having a problem when trying to upload a CSV file and populate a MySQL database.
The code below reads in the data from the file:
foreach($contents as $line) {
$line = str_replace('"', '', $line);
$fields = explode(',', $line);
$locoNo =$fields[0];
$name= $fields[1];
$updateStmt = "UPDATE $tableName set
NAME='$name',
DATE='$date' WHERE LOCONO='$locoNo' ";
if (!mysql_query($updateStmt, $link)) {
echo("Error updating database\n");
// echo($updateStmt);
exit();
}
}
the problem is in the $field[1] when the text contains a " ' " (apostrophe). This causes an error - and obviously my code handles this. How do I get the MsSQL to accept the " ' " as part of the query?
eg, one line from the CSV may be:-
87001, Royal Scot,
then the next line might be
87013, John o' Gaunt,
and it falls over at the " ' "
Help! How do I handle this special character?
Many thanks
SJP
ps. I know that phpBB may not format this correctly - sorry for that!