0
I’m trying to pass a JSON (result of a Google Place API) with Ajax to PHP. I believe my problem is in PHP when manipulating the data, follows a part of the code:
AJAX:
//GRAVA TODO O RETORNO NO BANCO...
$.ajax({
types: 'GET',
dataType: "json",
url: 'http://'+VARendereco+'/WB_CADASTRO_USUARIO3/www/busca.php',
data: "dados="+Dados_json+"&acao=salva_toda_busca_web",
success: function(data){
//alert(data[0].status);
//$('#sub-pagina').html(data);
//alert(data);
alert("Gravou_busca2");
}
});
PHP:
if($_GET["acao"] == "salva_toda_busca_web"){
//$matriz = stripslashes($_GET["dados"]);
$matriz = json_decode($_GET["dados"], true);
$itens = $matriz['results'];
//foreach ( $itens as $e ){
$SQL = "INSERT INTO tb_busca_geral (conteudo_busca, id_usuario, qt_resultados, local, lat, lon)VALUES('".$itens['name']."', 10, 5, '', '', '')";
$num = mysqli_query($serve, $SQL);
//echo $itens->name;
//}
}
It records the record, more blank in this field... If anyone has any ideas, I’d appreciate it!
json (example Google, in this format):
It may be a typo, you wrote there: $$_GET["data"] , and the correct is: $_GET["data"]
– Viniam
Thanks Viniam, but it was only time to copy and paste right here, I’ve reviewed, plus it saves the record in mysql... only blank!
– Rodrigo
gives a var_dump($_GET["data"] ) before writing to mysql to see where you’re losing that information
– Gabriel Rodrigues
Do the following: delete the 2 final lines, and echo the $items and check that the data is being received correctly, if everything is correct, Try this: $SQL = 'INSERT INTO tb_busca_geral (conteudo_busca, id_usuario, qt_resultados)VALUES("'.$items['name']'.'", 10, 5)',,,REMEMBERING: if all fields are varchar put everything including the numbers in double quotes.
– Viniam
Viniam, I echo and return blank to AJAX...
– Rodrigo
Follow the json result as Gabriel asked... Remembering that the json result of the request is ok, because I am working with it in other functions:
– Rodrigo
Sorry I can’t paste the return in json in question kkk... All wrong formatting appears
– Rodrigo
I put two images referring to the json that returns from the url, I’m manipulating it normally with javascript, the problem is in php!
– Rodrigo
dados_json is a JSON String or an Object already ?
– Hiago Souza
Command as an object yet, I try to convert with "json_decode" in php
– Rodrigo