2016-04-10 19 views
0

私は私のプロジェクトで私のログインモジュール上で動作するようにしようとしているが、それは常に応答がどのようなデータが含まれていないレスポンスにはデータが含まれていません。 PHPスクリプト

を返します。

私はindex.phpをを閲覧することができるよため、問題は私のDB_Functions.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); 
} 
?> 

のため?

+0

まず、 'spl_autoload_register()'を使い、 'mysql_'関数を使って2回目の停止をしてください。彼らは安定したバージョンに応じて廃止または削除されました – Rasclatt

+0

@Rasclattは情報に感謝しますが、締め切りは本当に近いですが、今は変更できません。 –

答えて

1

$tag != 'studentlogin'の場合は、この場合何もエコーしないため、else branchはありません。このソリューションは、ファイルの先頭にerror_reporting(E_ALL)を追加し、あなたの質問にデバッグ出力を追加しても解決できない場合

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

:あなたのコードは次のようにする必要があります。

関連する問題