Advertisement
annisa27

model login

Mar 1st, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. $response = array();
  4.  
  5.  
  6. // include db connect class
  7. require_once __DIR__ . '/db_connect.php';
  8.  
  9. // connecting to db
  10. $db = new DB_CONNECT();
  11.  
  12. if (isset($_GET["Username"], $_GET["Password"])) {
  13. $user = $_GET['Username'];
  14. $pass = $_GET['Password'];
  15. $result = mysql_query ("
  16. select
  17. id,
  18. username,
  19. password,
  20. hak_akses,
  21. kode
  22. from User
  23. where username = '$user'
  24. and password = '$pass'") or die(mysql_error());
  25. // check for empty result
  26. if (mysql_num_rows($result) > 0) {
  27. $response["Hasil"] = array();
  28. $row=0;
  29. while ($row = mysql_fetch_array($result)){
  30. $product = array();
  31. $product["ID"] = $row["id"];
  32. $product["Username"] = $row["username"];
  33. $product["Password"] = $row["password"];
  34. $product["HakAkses"] = $row["hak_akses"];
  35. $product["Kode"] = $row["kode"];
  36.  
  37. // push single product into final response array
  38. array_push($response["Hasil"], $product);
  39. }
  40. // success
  41. $response["success"] = 1;
  42.  
  43. // echoing JSON response
  44. echo json_encode($response);
  45. } else {
  46. // no Hasil found
  47. $response["success"] = 0;
  48. $response["message"] = "Hasil Tidak Ditemukan";
  49.  
  50. // echo no users JSON
  51. echo json_encode($response);
  52. }
  53. } else {
  54. // Hasil Tidak Di Ditemukan
  55. $response["success"] = 0;
  56. $response["message"] = "Hasil Tidak Di Ditemukan";
  57.  
  58. // Menampilkan Respon JSON
  59. echo json_encode($response);
  60. }
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement