在php中显示空结果的Json_编码

在php中显示空结果的Json_编码,php,mysql,json,mysqli,Php,Mysql,Json,Mysqli,我使用的是PHP7.1的最新版本。在这个PHP脚本中,得到的结果为空,响应为成功。但是如果我们使用print\r它会在输出中显示数组值 <?php include 'dbconn.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") { $inputJSON = file_get_contents('php://input'); $data=json_decode($inpu

我使用的是PHP7.1的最新版本。在这个PHP脚本中,得到的结果为空,响应为成功。但是如果我们使用print\r它会在输出中显示数组值

   <?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);
        }

    }
    ?>

请用方法检查错误


这应该解决问题,什么是错的去。如果仍然不知道,则使用输出更新您的帖子。

显示您的输出?您的代码易受SQL注入攻击,您需要修复此问题。您似乎还以明文形式存储密码,这是一个重大的安全风险。它们需要安全地散列。Outpu显示空@ZaidBinKhalid$yourvariable->providerEmail尝试这样获得响应值。好的,但如果它的数据量很大,很难获得每个列的解析。我在代码中添加了此代码,但仍然是空的@Timitao我在web服务器中使用PHP7.1.3。最新版本有问题吗版本?请提供您的测试输入。您向服务器发送什么json?你可以在chrome中使用,然后更新帖子。
$inputJSON = file_get_contents('php://input');
$data=json_decode($inputJSON, true);
if (!is_array($data) || empty($data)) {
    throw new Exception(json_last_error_msg());
}