dimanche 8 mai 2016

PDO query returns no result when querying the mysql database

Im developing an Android app which uses mysql database to store information. When I have the following function in my php code:

/*
 * Get User details
 * 
 */
public function getUserDetailsEse($email)
{
   $stmt = $this->conn->prepare("
SELECT u.title
     , u.name
     , u.surname
     , s.reg_num
     , s.barcode
     , s.prog
     , s.yos
     , s.sem
     , s.nat_id
     , s.dob
     , s.mobile
     , s.email
     , s.addr
     , s.registad_courses 
  FROM `users` u
     , `students` s 
 WHERE u.id=s.uza_id 
   AND s.email= ?
");

$stmt->bind_param("s", $email);

$stmt->execute();

if ($stmt->num_rows > 0) {
        // user existed 
        echo 'Query ran but nun';
        $stmt->close();
        return true;
    } else {
        // user not existed
        echo 'Query ddnt run';
        $stmt->close();
        return false;
    }

$stmt->close();
}

In which I want to fetch those details from the mysql database,then display them in my sqlite database to be used inside the app. I then call the function using:

$details = $db->getUserDetailsEse($email);

if ($details!=FALSE){
    $response1["error"] = FALSE;
    $response1["id"] = $details["id"];
    $response1["details"]["title"] = $details["title"];
    $response1["details"]["name"] = $details["name"];
    $response1["details"]["surname"] = $details["surname"];
    $response1["details"]["reg_num"] = $details["reg_num"];
    $response1["details"]["barcode"] = $details["barcode"];
    $response1["details"]["prog"] = $details["prog"];
    $response1["details"]["yos"] = $details["yos"];
    $response1["details"]["sem"] = $details["sem"];
    $response1["details"]["nat_id"] = $details["nat_id"];
    $response1["details"]["dob"] = $details["dob"];
    $response1["details"]["mobile"] = $details["mobile"];
    $response1["details"]["email"] = $details["email"];
    $response1["details"]["addr"] = $details["addr"];
    $response1["details"]["registad_courses"] = $details["registad_courses"];
    echo json_encode($response1);
}  else {
    $response1["error"] = TRUE;
    $response1["error_msg"] = "Failed to fetch details. Login credentials are wrong. Please try again!";
    echo json_encode($response1);
}

When i run the query in phpmyadmin it works fine: enter image description here

But when i try to run it on Postman, i get the following error: enter image description here

Here are the 2 table I'm querying: enter image description here

enter image description here

EDIT:TRYING TO PRINT $DETAILS enter image description here

Aucun commentaire:

Enregistrer un commentaire