Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user="root";
  4. $pass="";
  5. $host="localhost";
  6. $dbnamne="near_deal27";
  7.  
  8. $username = $_REQUEST['username'];
  9. $password = $_REQUEST['password'];
  10.  
  11. /*$username = 'i';
  12. $password = 'a';
  13. */
  14. //create connection
  15. $conn = new mysqli($host, $user, $pass, $dbnamne);
  16.  
  17. //check connection
  18. if($conn->connect_error){
  19. die("connection failed" .$com->connect_error);
  20. }
  21.  
  22. $sql = "SELECT * FROM user WHERE username='{$username}' AND password='{$password}' LIMIT 1";
  23.  
  24. $result = $conn->query($sql);
  25. $user = array();
  26.  
  27. while($row =$result->fetch_assoc()){
  28. $user = $row;
  29. }
  30.  
  31. if (!empty($user)) {
  32. # code..
  33. echo json_encode(array(
  34. 'success' => true,
  35. 'user' => $user
  36. ),JSON_NUMERIC_CHECK);
  37. }else{
  38. # code...
  39. echo json_encode(array(
  40. 'success' => true,
  41. 'user' => [
  42. 'id'=>0,
  43. 'username'=>'',
  44. 'password'=>''
  45. ]
  46. ),JSON_NUMERIC_CHECK);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement