I'm trying to parse a number of CSV files from a product feed. I'm using the code below to grab the data from the CSV, and process row by row for insertion in to a MySQL db. For some reason every once and a while the addslashes function seems to skip the escape sequence. What am I doing wrong here?
while (($data = fgetcsv($fh, 2000, ",")) !== FALSE)
{
$num = count($data);
$nl = 0;
for ($c=0; $c < $num; $c++)
{
$nl++;
if ($c >= 0)
{
if ($nl == 1)
{
$Name = addslashes($data[$c]);
}
if ($nl == 2)
{
$URL = $data[$c];
}
if ($nl == 3)
{
$CatalogName = addslashes($data[$c]);
}
if ($nl == 4)
{
$LastUpdated = $data[$c];
}
}
}
if ($headerRow > 40)
{
$sql = "INSERT INTO table (name,url,catname,updated) VALUES ('$Name','$URL','$CatalogName','$LastUpdated')";
mysqli_query($connection3,$sql) or die("Can't execute query I001.);
}
}