Good afternoon everyone.
I have made a php script to parse an XML file but this file in some of its fields contains the character ', which comes into conflict with the PHP code. At the moment I deleted this character from the XML file but I would like it to be stored in the DB.
I do not know if I should modify the XML file, putting something in front of the character so that when I read it the script does not enter into a conflict, or I must put something in the php script to free it. Can you help me?
I leave the php script:
$fichero = "./obras.xml";
if(!$xml = simplexml_load_file($fichero))
{
echo "No se ha podido cargar el archivo <br>";
}
else
{
echo "El archivo se ha cargado correctamente <br>";
}
include"./conectar.php";
$enlace= conectarse();
function Mayus($variable) {
$variable = strtr(strtoupper($variable),"àèìòùáéíóúçñäëïöü","ÀÈÌÒÙÁÉÍÓÚÇÑÄËÏÖÜ");
return $variable;
}
mysql_query("SET NAMES utf8");
foreach ($xml as $obra)
{
$obra = (array) $obra;
$ninv = $obra['ninventario'];
$ninv = Mayus($ninv);
$contrato = Mayus($obra['contrato']);
$desc = Mayus($obra['titulo']);
$consulta ="INSERT INTO 'ficha' ('ninv', 'contrato', 'desc') VALUES ('".$ninv."','".$contrato."','".$desc."')";
$resultado = mysql_query($consulta) or die(mysql_error()) ;
echo mysql_errno($enlace);
}
The error that occurs if the XML has the character 'is of this style:
You have an error in your SQL syntax near '12345678, 123.04, 0,)' at line 2
Thank you very much.