The purpose of my code is extract data from an CSV file and upload it into my DB.
I can extract all attributes from each line from the file but it keeps showing an error on the sql query.
Here is my PHP file:
<?
$row = 1;
$server="XXXXX";
$user="XXXX";
$password="XXXX";
$db="XXXX";
mysql_connect($server,$user,$password) or die('erreur au serveur');
mysql_select_db($db) or die('erreur db');
if (($handle = fopen('XXXX/articles.csv','r+')) !== FALSE) {
while (($data = fgetcsv($handle,";")) !== FALSE) {
$num = count($data);
//echo "<p> $num champs à la ligne $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
$produit =$data[$c];
$att = explode(";", $produit);
$prod = $att[0]; echo 'id = '.$prod .'<br/>';
$code = $att[1]; echo 'code = '.$code.'<br/>';
$nom = $att[2]; echo 'nom = '.$nom.'<br/>';
$cat = $att[3]; echo 'categorie = '.$cat.'<br/>';
$prix = $att[4]; echo 'prix = '.$prix.'<br/>';
$cond = $att[5]; echo 'cond = '.$cond.'<br/>';
$date = $att[6]; echo 'date = '.$date.'<br/>';
$qtes = $att[7]; echo 'qtes = '.$qtes.'<br/>';
$photo = $att[8]; echo 'photo = '.$photo.'<br/>';
$qte = $att[9]; echo 'qte = '.$qte.'<br/>';
$cam = $att[10]; echo 'camion = '.$cam;
$sql = 'UPDATE produit SET code_barre ='.$code.',nom_prod ='.$nom.', photo ='.$photo.',categorie='.$cat.',condition ='.$cond.',prix_uniraire ='.$prix.', date_exp='.$date.' ,qte ='.$qte.',qte_stock ='.$qtes.', id_camion= '.$cam.' WHERE id_prod ='.$prod.'';
$res = mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);
$row++;
}
}
fclose($handle);
}
?>
this is what I get :
Notice: 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 'condition =emballés,prix_uniraire =3450, date_exp=04/02/2016 ,qte =200,qte_stock' at line 1 in UPDATE produit SET code_barre =345123,nom_prod =Nutella, photo =www.google.com,categorie=Chocolat,condition =emballés,prix_uniraire =3450, date_exp=04/02/2016 ,qte =200,qte_stock =2100, id_camion= 2 WHERE id_prod =3 in /home/a2258793/public_html/seekarticles.php on line 34