$result = $dbFunctions->login($username, $password); if ($result) { $response["error"] = FALSE; $response["user"]["username"] = $username; $response["user"]["password"] = $password; echo json_encode($response); } else { $response["error"] = TRUE; $response["error_msg"] = "Incorrect username or password"; echo json_encode($response); } } else { if ($tag == 'register') { $username = $_POST['username']; $password = $_POST['password']; if ($dbFunctions->isUserExist($username)) { $response["error"] = TRUE; $response["error_msg"] = "User already exist"; echo json_encode($response); } else { $result = $dbFunctions->register($username, $password); if ($result) { $response["error"] = FALSE; $response["success_msg"] = "Registration successful"; $response["user"]["username"] = $username; $response["user"]["password"] = $password; echo json_encode($response); } else { $response["error"] = TRUE; $response["error_msg"] = "An error occured during registration"; echo json_encode($response);