<?php
session_start();
require_once 'connect.php';
$full_name = $_POST['full_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$password = $_POST['password'];
$password_confirm = $_POST['password_confirm'];
$result = mysqli_query($connect, "SELECT * FROM users WHERE `phone` = '".$phone."'");
if(@mysqli_num_rows($result) > 0 )
{
$_SESSION['message'] = 'Такой пользователь уже существует!';
}
if ($password === $password_confirm) {
$path = 'uploads/' . time() . $_FILES['avatar']['name'];
if (!move_uploaded_file($_FILES['avatar']['tmp_name'], '../' . $path)) {
$_SESSION['message'] = 'Ошибка при загрузке сообщения';
header('Location: ../register.php');
}
$password = md5($password);
mysqli_query($connect, "INSERT INTO `users` (`id`, `full_name`, `phone`, `password`, `avatar`) VALUES (NULL, '$full_name', '$phone', '$password', '$path')");
$_SESSION['message'] = 'Регистрация прошла успешно!';
header('Location: ../index.php');
} else {
$_SESSION['message'] = 'Пароли не совпадают';
header('Location: ../register.php');
}
?>