So I have no idea what the deal is here... the following code below produces the mysql error following the code.
$fcontents = file("inventory.csv");
for ($i = 1; $i < sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(',', $line);
$values = implode(',', $arr);
$values = str_replace('&', 'and', $values);
$sql = 'INSERT INTO inventory (dealerid, name, vin, stock, newused, year, ' .
'make, model, series, body, color, intcolor, price, retailprice, ' .
'miles, transmission, engine, restraint, certified, photourl, ' .
'comments, flag, options, citympg, hwympg) ' .
'VALUES mysql_real_escape_string(' . $values . ')';
mysql_query($sql);
echo $sql.'<br><br>';
if (mysql_error()) {
echo mysql_error() .'<br><br>';
}
}
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
RESOLVED!!! So I wanted to post the solution to the stupid, dumb single quote, double quote glitch when dumping a .csv file in mysql... See below.:
$fcontents = file("http://pathtofile.com/inventory.csv"); for($i=1; $i < sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(",", $line); $arr = str_replace ("'","'", $arr); $values = implode("','", $arr); $values = str_replace("\"',",'\'",', $values); $values = str_replace(",'\"",',"\'', $values); $values = str_replace("&", "and", $values); $sql = "INSERT INTO vehicles.inventory (dealerid,name,vin,stock,newused,year,make,model,series,body,color,intcolor,price,retailprice,miles,transmission,engine,restraint,certified,photourl,comments,flag,options,citympg,hwympg) VALUES ('".$values."')"; mysql_query($sql);