Issues while trying to send data to Web server

45 views Asked by At

I need to send data to my web server and unfortunately i'm not able to do that. I've spent like hours figuring out whats wrong and didn't make anything of it.

I'm trying to login a user using my web service. Here is my php script

<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// json response array
$response = array("error" => FALSE);

if (isset($_POST['email']) && isset($_POST['password'])) {

    // receiving the post params
    $email = $_POST['email'];
    $password = $_POST['password'];

    // get the user by email and password
    $user = $db->getUserByEmailAndPassword($email, $password);

    if ($user != false) {
        // use is found
        $status = isset($response["status"]) ? $response["status"] : '';
        if($status == 'disabled' || $status == 'Disabled') {
            // user is disabled
            $response["error"] = TRUE;
            $response["error_msg"] = "Your account has been suspended, please contact the admin";
            echo json_encode($response);
        }
        else {
            $response["error"] = FALSE;
            $response["uid"] = $user["id"];
            $response["user"]["name"] = $user["first_name"];
            $response["user"]["email"] = $user["email_address"];
            $response["user"]["created_at"] = $user["date_time"];
            echo json_encode($response);
        }
    } else {
        // user is not found with the credentials
        $response["error"] = TRUE;
        $response["error_msg"] = "Username or password is incorrect";
        echo json_encode($response);
    }
} else {
    // required post params is missing
    $response["error"] = TRUE;
    $response["error_msg"] = "Required parameters email or password is missing!";
    echo json_encode($response);
}
?>

the getUserByEmailAndPassword() function in use is this:

public function getUserByEmailAndPassword($email, $password) {

        $stmt = $this->conn->prepare("SELECT _id, first_name, last_name, email, profile_picture, is_verified, phone, is_admin, gender, access_token FROM users WHERE email = ? and password = ?");
        $stmt->bind_param("ss", $email, $password);

        if ($stmt->execute()) {
            $user = $stmt->get_result()->fetch_assoc();
            $stmt->close();

            // check for password equality
            // if ($password == $user['password']) {
                // user authentication details are correct
                return $user;
            // }
        } else {
            return NULL;
        }
    }

When a post request is made to it, this is the response i get enter image description here

Even if i do provide the email and password, the issue persists. The response specifies that no email or password was provided.

Any sort of help/hint would really be appreciated here.

0

There are 0 answers