registration.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require $_SERVER['DOCUMENT_ROOT']. '/services/connect.php';
  3. $_POST = json_decode(file_get_contents('php://input'), true);
  4. $name = $_POST["name"];
  5. $surname = $_POST["surname"];
  6. $address = $_POST["address"];
  7. $email = $_POST["email"];
  8. $password = $_POST["password"];
  9. $hash = password_hash($password, PASSWORD_DEFAULT);
  10. $query = "INSERT INTO users (`name`, `surname`, `address`, `email`, `password`)" .
  11. " VALUES ('$name', '$surname', '$address', '$email', '$hash')";
  12. $result = $mysql->query($query);
  13. if(!$result){
  14. echo "Произошли неполадки: ". $mysql->error;
  15. }
  16. //Response
  17. $query = "SELECT * FROM users WHERE `email` = '$email' ";
  18. $result = $mysql->query($query);
  19. if(!$result){
  20. echo "Произошли неполадки: ". $mysql->error;
  21. }
  22. $id = $result->fetch_assoc()["id"];
  23. $data = [
  24. "id" => $id,
  25. "name" => $name,
  26. "surname" => $surname,
  27. "address" => $address,
  28. "email" => $email,
  29. "rezult" => true,
  30. ];
  31. header('Content-Type: application/json; charset=utf-8');
  32. echo json_encode($data);
  33. ?>