I have an Android application that sends a Json as a string to the server in PHP. I've 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 got an error when I try to include this array in Mysql. I've 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= "";
$useExercise = array();
//var_dump($info);
foreach($json['Patient'][0] as $name){
$login = $name;
}
foreach ($json['Patient'][1]as $exercise){
$useExercise[] = array($exercise);
}
for ($i=0; sizeOf($useExercise) > $i; $i++){
$exercicies= mysqli_fetch_array($order);
$sql1 = ("UPDATE patient_exercise
INNER JOIN patients ON (patient_exercise.idpatient = patients.ID)
INNER JOIN exercises ON (exercises.idexercises = patient_exercise.idexercise)
SET patient_exercise.use_exercise=$useExercise[$i]
WHERE patient_exercise.idexercise= {$exercises['idexercise']} AND
patients.ID=(SELECT c.ID FROM (SELECT * FROM patients ) as c
WHERE c.login_patients = '$login');");
mysqli_query($connect, $sql1);
}
}
the error occurs on SET patient_exercise.use_exercise=$useExercise[$i]
And my Json is:
{"Paciente":[{"Nome":"Rafael"},
{"Exercicios":[{"0":"1"},
{"1":"0"},
{"2":"0"}]}]
}
What could be wrong?