<?php
header("Content-Type:application/json");
if (isset($_GET['username']) && isset($_GET['password'])) {
    include('db.php');
    include('EncryptDecrypt.php');

    $mcrypt = new MCrypt();
    $username = $_GET['username'];
    $password = $_GET['password'];

    $result = mysqli_query(
        $con,
        "SELECT * FROM `user_account` WHERE login_id='$username'"
    );
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_array($result);

        $password1 = $mcrypt->decrypt($row['password']);
        if ($password1 == $password) {
            $user_id = $row['user_id'];
            $first_name = $row['first_name'];
            $mobile_no = $row['mobile_no'];
            response($order_id, $user_id, $first_name, $mobile_no);
        }else{
            //response(NULL, NULL, 200, "No Record Found");
            echo "Error";
        }
        mysqli_close($con);
    } else {
        //response(NULL, NULL, 200, "No Record Found");
        echo "Error";
    }
} else {
    //response(NULL, NULL, 400, "Invalid Request");
    echo "Error";
}

function response($username, $user_id, $first_name, $mobile_no)
{
    $response['username'] = $username;
    $response['user_id'] = $user_id;
    $response['first_name'] = $first_name;
    $response['mobile_no'] = $mobile_no;

    $json_response = json_encode($response);
    echo $json_response;
}
