Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. //// ===============================================================================
  3. //// creating connection
  4. $servername = "";
  5. $username = "";
  6. $password = "";
  7. $dbname = "";
  8.  
  9. $conn = mysqli_connect($servername, $username, $password, $dbname);
  10. if (!$conn)
  11. {
  12. die("Connection failed: " . mysqli_connect_error());
  13. }
  14.  
  15. // catch raw data send with Content-Type header : application/json
  16. $json = file_get_contents('php://input');
  17. $data = json_decode($json);
  18.  
  19. $sql = "SELECT u.id
  20. FROM user_info u
  21. WHERE '$data->login' = u.login AND '$data->passwd' = u.passwd";
  22.  
  23. // execute query and check if error
  24. if(!($result = mysqli_query($conn, $sql)))
  25. {
  26. echo "$param Error: " . $sql . "<br>" . mysqli_error($conn);
  27. }
  28.  
  29. $id = -1;
  30. if(mysqli_num_rows($result)>0)
  31. {
  32. $row = mysqli_fetch_assoc($result);
  33. $id = $row['id'];
  34. }
  35. $id = array("id"=>$id);
  36.  
  37. echo json_encode($id);
  38.  
  39. mysqli_close($conn);
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement