I am reading a comma delimited file into php to insert into a MySql database as follows:
<?
$fcontents = file ('file.csv');
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "insert into TABLENAME values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>
Everything is acting as expected. The only problem is that it seems to be looping on extra time and giving me a blank set of results at the end of each line and producing the following:
insert into TABLENAME values ('"name"','"random data"','"random data"','"random data",'','','','')
Do you know what might be the problem?
Thanks in advance