here is my userdata table
and below is my gfg.php code, I changed my table name machin1 with userdata (when i was trying diff solution)
// Get the user id
$city = $_REQUEST['city'];
// Database connection
$con = mysqli_connect("localhost", "root", "", "gfg");
if ($city !== "") {
// Get corresponding first name and
// last name for that user id
$query = mysqli_query($con, "SELECT first_name,
last_name FROM userdata WHERE city='$city'");
$row = mysqli_fetch_array($query);
// Get the first name
$first_name = $row["first_name"];
// Get the first name
$last_name = $row["last_name"];
}
// Store it in a array
$result = array("$first_name", "$last_name");
// Send in JSON encoded form
$myJSON = json_encode($result);
echo $myJSON;
?>