I created this PHP code to do a search in a database with data in person, but every time I run it gives me this error and I do not understand why.
<?php
$host='localhost';
$username='user';
$pwd='password';
$db='PersonDB';
$responce = array();
$responce ["success"]= 0 ;
$responce ["message"]= "Error at start";
global $found;
if (isset($_POST['idperson']) && isset($_POST['name']) && isset($_POST['surname'])){
$idperson = $_POST['idperson'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$connect = mysqli_connect($host,$username,$pwd,$db) or die ('Unabletp connect');
if (mysqli_connect_error($connect)){
echo(" Fallita la connessione al database".mysqli_connect_error());
}
$sql_find = ("SELECT CITY, ADRESS, CAP FROM PEOPLE WHERE ID_PERSON = $idperson' AND NAME_PERSON = '$name' AND SURNAME = '$surname' ") ;
print $sql_find;
$result= mysqli_query($connect,$sql_find) or die ("Error:".mysqli_error($connect)." with query ");
if($result){
$found=true;
while ($row = mysql_fetch_array($result)){
array_push($response, array("CITY"=>$row["CITY"],"ADRESS" = >$row["ADRESS"],"CAP" => $row["CAP"],"FOUND" => $found));
}
echo json_encode($response);
} else {
$responce ["success"]= 0 ;
$responce ["message"]= "Person not found";
} else {
$response['success']=0;
$response['message']="Parameters are not correct";
echo json_encode($response);
}
}
mysqli_close($connect);
?>
Printing the query the data is passed correctly but I do not understand why! do not need array_push()
to send my json file containing the data found to my app ?
Thanks for your help!