Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <?php
  2.  
  3. class DB_Functions {
  4.  
  5. private $db;
  6.  
  7. function __construct() {
  8.  
  9. require_once 'db_connect.php';
  10.  
  11. $this->db = new DB_Connect();
  12. $this->db->connect();
  13. }
  14.  
  15. public function getUser($uid, $password) {
  16. $result = mysql_query("SELECT * FROM users WHERE id = '$uid' AND pswd = '$password'") or die(mysql_error());
  17.  
  18. $no_of_rows = mysql_num_rows($result);
  19. if ($no_of_rows > 0) {
  20.  
  21. $result = mysql_fetch_array($result);
  22. return $result;
  23.  
  24. } else {
  25.  
  26. return false;
  27. }
  28. }
  29.  
  30. }
  31.  
  32. ?>
  33.  
  34. <?php
  35.  
  36. class DB_Functions {
  37.  
  38. private $db;
  39.  
  40. function __construct() {
  41.  
  42. require_once 'db_connect.php';
  43.  
  44. $this->db = new DB_Connect();
  45. $this->db->connect();
  46. }
  47.  
  48. public function getUser($uid, $password) {
  49. $stmt = $db->prepare("SELECT * FROM users WHERE id=? AND pswd=?");
  50. $stmt->execute(array($uid, $password));
  51. return $stmt->fetch();
  52. }
  53.  
  54. }
  55.  
  56. ?>
  57.  
  58. require_once 'include/db_functions.php';
  59. $db = new DB_Functions();
  60.  
  61.  
  62. if ($tag == 'login') {
  63.  
  64. $uid =mysql_real_escape_string($_POST['id']);
  65. $password =mysql_real_escape_string($_POST['pswd']);
  66.  
  67. // check for user
  68. $user = $db->getUser($uid, $password);
  69.  
  70. if ($user != false) {
  71.  
  72. $response["success"] = 1;
  73. $response["user"]["id"] = $user["id"];
  74.  
  75. echo json_encode($response);
  76. } else {
  77.  
  78. $response["error"] = 1;
  79. $response["error_msg"] = "Incorrect email or password!";
  80. echo json_encode($response);
  81. }
  82.  
  83. if ($tag == 'login') {
  84.  
  85. // check for user
  86. $user = $db->getUser( $_POST['id'], $_POST['pswd']);
  87.  
  88. ... etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement