I have an Android application that sends a Json in the form of a string to the server in PHP. I tested with var_dump to verify that the data was being passed correctly and everything is ok. The problem is that when I try to access json and assign values from a nested array of the main object to an array in PHP, I have an error trying to include this array in Mysql. Before doing 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 JSON framework I set up here because I could not move to a specific file, but I believe it is correct.