1
How do I perform an Insert in php where the data is passed by a json that has in the object a nonprimitive variable.
This is my Json
{"id":0,"latitude":-8.0326941,"longitude":-34.9287402,"status":1,
"tipovaga":{"descricao":"no aplication","id":5},
"usuario":"email":"[email protected]","id":14,"nome":"nome","palavrasecreta":"secreto","password":"XXXX"}
}
This is a webservice
$stmt = $conn->prepare("INSERT INTO flanelinha_db.HistoricoVaga (tipo_vaga,usuario, latitude, longitude, status, endereco, bairro, cidade, estado) VALUES (?,?,?,?,? , null,null,null,null)");
$json = json_decode(include("novavaga.json"));
$tipovaga = $json ->{'tipovaga'};
$usuario = $json->{'usuario'};
$latitude = $json->{'latitude'};
$longitude = $json->{'longitude'};
$status = $json->{'status'};
$stmt->bind_param("iiddi", $tipovaga, $usuario, $latitude, $longitude ,$status);
$stmt->execute();
$stmt->close();
$id = $conn->insert_id;
I need to save the PK id of type and user in the database.
json is not valid missing a "{" in "user"
– Fábio