Okay, here is the whole file handle. It works aon all csv files except one unexplicably.
I did not use mysql_real_escape_string because is an internal conversion and all files are internal excel spreadsheets. I used csv format to upload so I had to trap for commas and apostrophe's in the cells. I did try the commented out line using mysql_real_escape_string.
I got this error:
rror: syntax error, unexpected T_CONCAT_EQUAL in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\tools\cart_inventory_form\uploader4.php on line 66
Line 66 is the mysql_real_escape_string line.
$fh = fopen($target_path, 'r+') or die("Can't open file");
//$filesize=filesize($target_path);
$i=0;
while(!feof($fh)) {
$res = fgetcsv($fh, "," );
$sData='';
if ( (empty($res)) ) { break; }
if ( $i==0 ) {
foreach ($res as $key => $value) {
$hdr.=",$value";
}
$hdr=substr($hdr,1);
}else{
// for ( $t=0;$t>count($res);$t++) {
foreach ($res as $key => $value) {
// $sData.=",'" . str_replace("'","''",$value) . "'";
sData.=",'" . mysql_real_escape_string($value) . "'";
}
$sData=substr($sData,1);
$sql="INSERT INTO cart_order.inventory(control_id, bu, cart_id, $hdr) VALUES ($controlID, '$bu', '$cart_id',$sData)";
echo "$sql<br />";
// echo "<b>" . $sData . "</b><br>";
$result=mysql_query($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br>$sql");}
}
$i++;
}
// $aLines[$i]=$line;
// $i++;
//}
fclose($fh);
THANKS!