0
I have an Android application that sends a string-shaped Json to the PHP server. I tested with var_dump to check that the data was being passed correctly and everything is ok. The problem is that when trying to access json and assign values from a nested array of the main object to a PHP array, I have an error in trying to include this array in Mysql. Before making this inclusion, I tested only PHP and Mysql and everything is working perfectly.
if (!empty($_POST)){
$info = file_get_contents('php://input');
$json = json_decode($info, true);
$login= "";
$utilizaExercicio = array();
//var_dump($info);
foreach($json['Paciente'][0] as $nome){
$login = $nome;
}
foreach ($json['Paciente'][1]as $exercicio){
$utilizaExercicio[] = array($exercicio);
}
for ($i=0; sizeOf($utilizaExercicio) > $i; $i++){
$exercicios = mysqli_fetch_array($ordernar);
$sql1 = ("UPDATE exercicio_paciente
INNER JOIN pacientes ON (exercicio_paciente.idpaciente = pacientes.ID)
INNER JOIN exercicios ON (exercicios.idexercicios = exercicio_paciente.idexercicio)
SET exercicio_paciente.utilizar_exercicio=$utilizaExercicio[$i]
WHERE exercicio_paciente.idexercicio= {$exercicios['idexercicio']} AND
pacientes.ID=(SELECT c.ID FROM (SELECT * FROM pacientes) as c
WHERE c.login_paciente = '$login');");
$salvo = mysqli_query($connect, $sql1);
if ($salvo)
$sucesso = 1;
else
$sucessoLocal=0;
}
}
Here, the error happens in SET exercicio_paciente.utilizar_exercicio=$utilizaExercicio[$i]
And my json:
{Paciente:[{"Nome":"Rafael"},
{Exercicios:[{"0":"1"},
{"1":"0"},
{"2":"0"}]}]
}
What would be wrong? NOTE: The structure of JSON I built here, because I could not pass to a specific file, but I believe it is correct.
Pardon me for asking, but would you still need to manipulate these entrances? I put the 3 and in all appeared the following error: "Cannot use Object of type mysqli_result as array". <br/> "". print_r($utilizaExercicio[$i], true)."" The tabs would be positioned correctly]?
– Rodrigo Ferraz