0
I have a code PHP
which causes an array to become jSON
<?php
$imagens = array('imagem1.jpg', 'imagem2.jpg', 'imagem3.jpg');
$json = json_encode($imagens);
$inserir = mysql_query("INSERT INTO table VALUES ('$nome', '$descricao', '$foto', '".$json."'));
?>
But when running this query, PHP returns me:
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 '72249.jpg ", "66462.jpg ", "84186.jpg ", "96462.jpg ", "80447.jpg "] ")' at line 1
I have this problem, but I don’t know what it could be.
It seems that json is generating a wrong syntax in Insert, perhaps because of a slider
\
– rray
@How can I fix this ?
– Alisson Acioli
Places the generated sql.
– rray
You want the "Create Table..." ?
– Alisson Acioli
Do it like this:
$sql = "INSERT INTO table VALUES ('$nome', '$descricao', '$foto', '$json'"; echo $sql; mysql_query($sql) or die(mysql_error());
– rray
INSERT INTO acoluna_casos VALUES (\"\", \"teste\", \"<p>testandooo<\/p>\r\n\", \"36681.jpg\", \"[\"06004.jpg\",\"96354.jpg\",\"03715.jpg\",\"87790.jpg\",\"72602.jpg\"]\")
This is the real command I’m using– Alisson Acioli