Is there anyone out there that could assist me in getting this script to work properly.
It will take the file scoring.txt (tab delimited file) and import it into the database BUT take a look at this example of what the file has:
I am using [TAB] to state that there is a TAB between variables.
03-03-2004[TAB]"ABC Restaurant"[TAB]good
03-03-2004[TAB]"Bob's Restaurant"[TAB]good
This code is being exported from an access file in this format so I can not change it. Note that the middle column has "" around the variable.
What is happening is it finds that apostraphe in Bob's and not liking it.
Is there any way to fix this as the apostraphe can not be stripped out.
<?
include("db_connect.php");
# first get a mysql connection as per the FAQ
$fcontents = file ('scoring.txt');
# expects the csv file to be in the same dir as this script
echo "Starting to import file<P>";
for($i=1; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ';'
$sql = "insert into stock_scoring values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<P>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
echo "<BR>Finished importing<BR>";
?>