响应不包含任何数据.PHP脚本


Response does not contain any data. PHP Script

我试图在我的项目中使用我的登录模块,但它总是返回

响应不包含任何数据

我认为问题出在我的DB_Functions.php上,因为我可以浏览index.php

DB_Functions.php的代码

<?php
class DB_Functions {
    private $db;
    //put your code here
    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $this->db = new DB_Connect();
        $this->db->connect();
    }
    // destructor
    function __destruct() {
    }
    public function getUserByEmailAndPasswordStudent($studentno, $password) {
        $result = mysql_query("SELECT * FROM students WHERE student_no = '$studentno'") or die(mysql_error());
        // check for result 
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            $result = mysql_fetch_array($result);
            $pass = $result['password'];
            // check for password equality
            if ($pass == $password) {
                // user authentication details are correct
                return $result;
            }
        } else {
            // user not found
            return false;
        }
    }
}

index.php的代码

<?php
if (isset($_POST['tag']) && $_POST['tag'] != '' && $_POST['tag'] != '') {
    // get tag
    $tag = $_POST['tag'];
    // include db handler
    require_once 'include/DB_Functions.php';
    $db = new DB_Functions();
    // response Array
    $response = array("tag" => $tag, "error" => FALSE);
    // check for tag type
    if ($tag == 'studentlogin') {
        // Request type is check Login
        $studentno = $_POST['studentno'];
        $password = $_POST['password'];
        // check for user
        $user = $db->getUserByEmailAndPasswordStudent($studentno, $password);
        if ($user != false) {
            // user found
            $response["error"] = FALSE;
            $response["user"]["studentid"] = $user["studentid"];
            $response["user"]["fname"] = $user["fname"];
            $response["user"]["mname"] = $user["mname"];
            $response["user"]["lname"] = $user["lname"];
            $response["user"]["student_no"] = $user["studentno"];
            $response["user"]["grade_level"] = $user["gradelevel"];
            $response["user"]["sectionid"] = $user["sectionid"];
            echo json_encode($response);
        } else {
            // user not found
            // echo json with error = 1
            $response["error"] = TRUE;
            $response["error_msg"] = "Incorrect email or password!";
            echo json_encode($response);
        }
    }
} else {
    $response["error"] = TRUE;
    $response["error_msg"] = "Required parameter 'tag' is missing!";
    echo json_encode($response);
}
?>

我的代码出了什么问题?

$tag != 'studentlogin'时,条件没有else branch,因为在这种情况下不回显任何内容。你的代码应该是这样的:

if ($tag == 'studentlogin') {
    /* your code here*/ 
} else { 
    echo json_encode($response);
}

如果此解决方案无法帮助在文件顶部添加error_reporting(E_ALL),并将调试输出添加到问题中。