12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- require $_SERVER['DOCUMENT_ROOT'].'/services/connect.php'; //Подключение connect.php
- $_POST = json_decode(file_get_contents('php://input'), true);
- //Пост запрос к БД на вставку
- $name = $_POST["name"];
- $surname = $_POST["surname"];
- $address = $_POST["address"];
- $email = $_POST["email"];
- $password = $_POST["password"];
- //Хешируем пароль, чтобы безопасно сохранить
- $hash = password_hash($password, PASSWORD_DEFAULT);
- $query = "INSERT INTO users (`name`, `surname`, `address`, `email`, `password`) VALUES ('$name', '$surname', '$address', '$email', '$hash')";
- $result = $mysql->query($query);
- if(!$result){
- echo "Произошли неполадки при регистрации: ". $mysql->error;
- }
- //Response
- $query = "SELECT * FROM users WHERE `email` = '$email'";
- $result = $mysql->query($query);
- if(!$result){
- echo "Произошли неполадки при получении email: ". $mysql->error;
- }
- $id = $result->fetch_assoc()["id"];
- $data = [
- "id" => $id,
- "name" => $name,
- "surname" => $surname,
- "address" => $address,
- "email" => $email,
- "result" => true
- ];
- header('Content-Type: application/json;charset=utf-8');
- echo json_encode($data);
|