Daria
03-20-2006, 07:04 PM
the script below allows me to upload text file straight into the mysql table
<?
$linkID = @mysql_connect(APP_DB_HOST, APP_DB_USER, APP_DB_PASSWORD) or die('Connection to Database FAILED.' . mysql_error());
mysql_select_db(APP_DB, $linkID);
$data = file ('./textfile.txt');
for($i=0; $i<sizeof($data); $i++) {
$line = trim($data[$i], '\t');
$arr = explode("\t", $line);
$sql = "insert into table values ('". implode("','", $arr) ."')";
mysql_query($sql);
echo $sql;
if(mysql_error()) {
echo "<h1>";
echo mysql_error() ."</h1";
}
}
?>
The problem is, when my data contains a single quote, that row does not go through, as a bad syntax. So for everything that says something to the extend of Mike's Place, stalls my file.
What should I modify to make sure the data with single quotes gets proper treatment, when it is a part of the file?
<?
$linkID = @mysql_connect(APP_DB_HOST, APP_DB_USER, APP_DB_PASSWORD) or die('Connection to Database FAILED.' . mysql_error());
mysql_select_db(APP_DB, $linkID);
$data = file ('./textfile.txt');
for($i=0; $i<sizeof($data); $i++) {
$line = trim($data[$i], '\t');
$arr = explode("\t", $line);
$sql = "insert into table values ('". implode("','", $arr) ."')";
mysql_query($sql);
echo $sql;
if(mysql_error()) {
echo "<h1>";
echo mysql_error() ."</h1";
}
}
?>
The problem is, when my data contains a single quote, that row does not go through, as a bad syntax. So for everything that says something to the extend of Mike's Place, stalls my file.
What should I modify to make sure the data with single quotes gets proper treatment, when it is a part of the file?