<?
header('Access-Control-Allow-Origin: *');

//var_dump(json_decode(file_get_contents("php://input")));
$postData = json_decode(file_get_contents("php://input"));

//echo 'Hello...here1' .'<br/>';
//echo 'Result:' . '<br/>';
//echo $postData->name;
//die();


$query = "SELECT * FROM users WHERE apptype = " .$postData->apptype. " AND userid = '" .$postData->userid. "' AND password = '" .$postData->password. "' ";
//echo 'query = ' .$query;
//die();

//$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

//$query = "SELECT * FROM users ";
$dbresult = $mysqli->query($query);

//echo 'Hello...here1';
//die();

$data = [];

while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
    $data[] = array(
        'apptype' => $row['apptype'],
        'userid' => $row['userid'],
        'password' => $row['password']
    );
}

$mysqli->close();

//echo 'Hello...here2';
//die();

if (sizeof($data) > 0) {
    http_response_code(200);
    $result = "{success:true}";
}
else {
    http_response_code(401);
    $result = "{success:false}";
}
 
echo $result;

?>