Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'include/DB_Functions.php';
  4. $db = new DB_Functions();
  5.  
  6. // json response array
  7. $response = array("error" => FALSE);
  8.  
  9. if (isset($_POST['name']) && isset($_POST['nis']) && isset($_POST['kelas']) && isset($_POST['password'])) {
  10.  
  11. // receiving the post params
  12. $name = $_POST['name'];
  13. $nis = $_POST['nis'];
  14. $kelas = $_POST['kelas'];
  15. $password = $_POST['password'];
  16.  
  17. // check if user is already existed with the same nis
  18. if ($db->isUserExisted($nis)) {
  19. // user already existed
  20. $response["error"] = TRUE;
  21. $response["error_msg"] = "User already existed with " . $nis;
  22. echo json_encode($response);
  23. } else {
  24. // create a new user
  25. $user = $db->storeUser($name, $nis, $kelas, $password);
  26. if ($user) {
  27. // user stored successfully
  28. $response["error"] = FALSE;
  29. $response["uid"] = $user["unique_id"];
  30. $response["user"]["name"] = $user["name"];
  31. $response["user"]["nis"] = $user["nis"];
  32. $response["user"]["kelas"] = $user["kelas"];
  33. $response["user"]["created_at"] = $user["created_at"];
  34. $response["user"]["updated_at"] = $user["updated_at"];
  35. echo json_encode($response);
  36. } else {
  37. // user failed to store
  38. $response["error"] = TRUE;
  39. $response["error_msg"] = "Unknown error occurred in registration!";
  40. echo json_encode($response);
  41. }
  42. }
  43. } else {
  44. $response["error"] = TRUE;
  45. $response["error_msg"] = "Required parameters (name, nis or password) is missing!";
  46. echo json_encode($response);
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement