Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'include/DB_Functions.php';
- $db = new DB_Functions();
- // json response array
- $response = array("error" => FALSE);
- if (isset($_POST['name']) && isset($_POST['nis']) && isset($_POST['kelas']) && isset($_POST['password'])) {
- // receiving the post params
- $name = $_POST['name'];
- $nis = $_POST['nis'];
- $kelas = $_POST['kelas'];
- $password = $_POST['password'];
- // check if user is already existed with the same nis
- if ($db->isUserExisted($nis)) {
- // user already existed
- $response["error"] = TRUE;
- $response["error_msg"] = "User already existed with " . $nis;
- echo json_encode($response);
- } else {
- // create a new user
- $user = $db->storeUser($name, $nis, $kelas, $password);
- if ($user) {
- // user stored successfully
- $response["error"] = FALSE;
- $response["uid"] = $user["unique_id"];
- $response["user"]["name"] = $user["name"];
- $response["user"]["nis"] = $user["nis"];
- $response["user"]["kelas"] = $user["kelas"];
- $response["user"]["created_at"] = $user["created_at"];
- $response["user"]["updated_at"] = $user["updated_at"];
- echo json_encode($response);
- } else {
- // user failed to store
- $response["error"] = TRUE;
- $response["error_msg"] = "Unknown error occurred in registration!";
- echo json_encode($response);
- }
- }
- } else {
- $response["error"] = TRUE;
- $response["error_msg"] = "Required parameters (name, nis or password) is missing!";
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement