I have a a small application that gets the catalog from an api and with that catalog I wanna safe every product in to my own DB. everything works fine except the description. If I try to push that into my DB I get the error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's handkerchiefs. Gradually, she became a true symbol of Italian pizzazz between ' at line 1
. I think its because sql doesn't accept punctuation marks but I'm not sure if that's the case
this is how I get the product ready to send it to my DB.php, everything goes fine until I send it to the DB
$xml = simplexml_load_string(file_get_contents($url));;
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$xml->saveXML();
$jsonList = json_decode(json_encode($xml));
//echo '<pre>'. print_r($xml->PRODUCT, true). '</pre>';
$lenght = count($xml);
$stack = array();
foreach($jsonList->PRODUCT as $product){
if($product->ID == 117758){
//var_dump($product);
array_push($stack, $product);
}
}
foreach ($stack as $products) {
SaveProduct($products);
}
And this is how I send it to the DB. (So this is my DB.php)
<?php
global $Connection;
function openConnection()
{
global $Connection;
$Connection = new mysqli("localhost", "root", "", "test");
$Connection->select_db("test");
if ($Connection->connect_error) {
die("Connection failed: " . $Connection->connect_error);
}
}
function SaveProduct($product){
openConnection();
global $Connection;
if(is_string($product->DESCRIPTION)){
$sql = "INSERT INTO product (`P_ID`,`Type`,`Manufacturer`,`Line`,`Name`,`Size`,`Variant`,`Variant_code`,`Variant_image`,`Sex`,`Image`,`Description`,`Price`,`Stock`,`Ean`,`Ean2`) VALUES ('".$product->ID."','".$product->TYPE."','".$product->MANUFACTURER."','".$product->LINE."','".$product->NAME."','".$product->SIZE."','NULL','NULL','NULL','".$product->SEX."','".$product->IMAGE."','".$product->DESCRIPTION."','".$product->PRICE."','".$product->STOCK."','".$product->EAN."','NULL')" or die("Error while adding product");
}
$result = $Connection->query($sql)or die($Connection->error);
echo $result;
}
This is a picture of an $product and the error that I am getting
If u need more information let me know and i'll update this question! :)