Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. include_once 'connection.php';
  3.  
  4. class User {
  5.  
  6. private $db;
  7. private $connection;
  8.  
  9. function __construct() {
  10. $this -> db = new DB_Connection();
  11. $this -> connection = $this->db->getConnection();
  12. }
  13.  
  14. public function does_user_exist($email,$haslo,$imie,$nazwisko)
  15. {
  16. $query = "SELECT from uzytkownicy WHERE email='$email' and haslo = '$haslo' ";
  17. $result = mysqli_query($this->connection, $query);
  18. if(mysqli_num_rows($result)>0){
  19. $json['success'] = ' Welcome '.$email;
  20. echo json_encode($json);
  21. mysqli_close($this -> connection);
  22. }else{
  23. $query = "INSERT INTO uzytkownicy (email,haslo,imie,nazwisko) VALUES ('$email','$imie','$nazwisko',MD5('$haslo'))";
  24. $inserted = mysqli_query($this -> connection, $query);
  25. if($inserted == 1 ){
  26. $json['success'] = 'Acount created';
  27. }else{
  28. $json['error'] = 'Wrong';
  29. }
  30. echo json_encode($json);
  31. mysqli_close($this->connection);
  32. }
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39. $user = new User();
  40. if(isset($_POST['email']) && isset($_POST['haslo']) && isset($_POST['nazwisko']) && isset($_POST['imie'])) {
  41. $email = $_POST['email'];
  42. $haslo = $_POST['haslo'];
  43. $nazwisko = $_POST['nazwisko'];
  44. $imie = $_POST['imie'];
  45.  
  46. if(!empty($email) && !empty($haslo) && !empty($imie) && !empty($nazwisko)){
  47.  
  48. $encrypted_password = md5($haslo);
  49. $user-> does_user_exist($email,$haslo,$imie,$nazwisko);
  50.  
  51. }else{
  52. echo json_encode("you must type both inputs");
  53. }
  54.  
  55. }
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement