<?php
if(!empty($_POST['opdnum']) && !empty($_POST['name']) && !empty($_POST['phone'])){
    /** get palces api */
    $url_getdata = 'http://117.240.62.146/iiislifelineobapi/srvBkAPI.asmx/getPatient?op_no='.$_POST['opdnum'].'&mobno='.$_POST['phone'].'&name='.$_POST['name'];
    // Fetch the XML content from the URL
    $xmlResponse_data = file_get_contents($url_getdata);
    if ($xmlResponse_data === false) {
        // Handle the error if the URL couldn't be fetched
        echo "Failed to fetch data from the URL.";
    } else {
        // Use SimpleXML to parse the XML response
        $xml_data= simplexml_load_string($xmlResponse_data);
        if ($xml_data === false) {
            // Handle XML parsing error
            echo "Failed to parse XML response.";
        } else {
            // Extract the JSON content from the XML element
            $jsonString_data = (string)$xml_data;
            // Decode the JSON string into a PHP array
            $data = json_decode($jsonString_data, true);
            if ($data === null) {
            // Handle JSON decoding error
            echo "Failed to decode JSON data.";
            } else {
            // print_r($data_getPlace);
            $op_no = $data['op_no'];
            $name = $data['Name'];
            $mobile = $data['mobile'];
            $email = $data['email'];

            $result = array(
                'op_no' => $op_no,
                'name' => $name,
                'mobile' => $mobile,
                'email' => $email,
            );

            header('Content-Type: application/json'); // Set the content type to JSON
            echo json_encode($result);

            }
        }
    }
}



// if (isset($_POST['inputValue'])) {
//     // Get the input value sent from the client
//     $inputValue = $_POST['inputValue'];

//     // Simulate database query and retrieve data based on $inputValue
//     // Replace this with your actual database query
//     $dataFromDB = fetchDataFromDB($inputValue);

//     // Prepare the response as an associative array
//     $response = array(
//         'data' => $dataFromDB,
//     );

//     // Send the JSON-encoded response
//     echo json_encode($response);
// } else {
//     echo "No input value received.";
// }

// function fetchDataFromDB($inputValue) {
//     // Perform a database query here based on $inputValue
//     // Replace this with your actual database query logic
//     // Example: $result = yourDatabaseQuery($inputValue);
    
//     // For this example, we simulate data from the database
//     $result = array(
//         'field1' => 'Value 1 for ' . $inputValue,
//         'field2' => 'Value 2 for ' . $inputValue,
//         'field3' => 'Value 3 for ' . $inputValue,
//     );

//     return $result;
// }
?>