0

I am using latest version of php 7.1. In this PHP script getting empty result with success response. But if we use print_r its showing array values in the output.

   <?php
    include 'dbconn.php'; 
    if ($_SERVER["REQUEST_METHOD"] == "POST") {

            $inputJSON = file_get_contents('php://input');
            $data=json_decode($inputJSON, true);
            $email=$data['providerEmail'];
            $password=$data['providerPassword'];

            if($data){

                $sql="select * from en_providers where providerEmailAddress='".$email."' and providerPW='".$password."'";
                $result = mysqli_query($con,$sql) or die("Error in Selecting " . mysqli_error($connection));
                $row =mysqli_fetch_assoc($result);
                $providerID=$row['providerID'];

                    $sql1="select * from en_venues where providerID='".$providerID."'";
                    $result1 = mysqli_query($con,$sql1) or die("Error in Selecting " . mysqli_error($connection));
                        while($row1['Doctorid'][] =mysqli_fetch_assoc($result1)){
                            $merge=array_merge($row,$row1);
                        }
            if($row){  
                header('WWW-Authenticate: Digest',true,200);   
                $list=$merge;
                echo json_encode($list);
            }
            else
            {
                header('WWW-Authenticate: Digest');
                header('HTTP/1.1 401 Unautherised', true, 401);
                $er='Invalid Username/Password';
                $return['error']=$er;
                echo json_encode($return);   
            } 
        }
        else
        {
            header('WWW-Authenticate: Digest');
            header('HTTP/1.1 401 Unautherised', true, 401);
            $er='Invalid Username/Password';
            $return['error']=$er;
            echo json_encode($return);
        }

    }
    ?>

How to print array values in json response.

please help me how to slove this issue. Thanks

saiibitta
  • 377
  • 2
  • 18

1 Answers1

0

Please, check you errors with method json_last_error_msg

$inputJSON = file_get_contents('php://input');
$data=json_decode($inputJSON, true);
if (!is_array($data) || empty($data)) {
    throw new Exception(json_last_error_msg());
}

This should resolve problem, what is wrongly go. If still won't know, then update you post with output.

timiTao
  • 1,417
  • 3
  • 20
  • 34
  • I added this code in my code but still its getting empty @timiTao – saiibitta May 17 '17 at 07:31
  • I am using php 7.1.3 in web server is there any problem with latest version? – saiibitta May 17 '17 at 07:38
  • Please, provide your input for testing. What json you send to server? You can use in chrome [Copy as Curl](https://coderwall.com/p/-fdgoq/chrome-developer-tools-adds-copy-as-curl) for that - update post then. – timiTao May 17 '17 at 07:42