<?php
$host = "provalgk.beget.tech";
$username = "provalgk_user";
$password = "Qwer123.";
$database = "provalgk_user";

// Получение введенного логина и пароля из формы
$user = $_POST['login'];
$pass = $_POST['password'];

// Подключение к базе данных
$mysql = new mysqli($host, $username, $password, $database);

// Проверка соединения
if($mysql->connect_error){
    die("Ошибка подключения". $mysql->connect_error);
}

// Подготовка запроса для проверки логина
$quary = "SELECT * FROM Login WHERE login like'$user' AND password like '$pass'";
$result = mysqli_query($mysql, $quary);
$row = mysqli_fetch_assoc($result);
$id = $row['id_user'];
$userpass = $row['password'];
$userlogin = $row['login'];
$role = $row['role'];
if (mysqli_num_rows($result) > 0) {  
    if($role == 1)   
    {
    session_start();
    $_SESSION['id'] = $id;
    $_SESSION['password'] = $userpass;
    $_SESSION['login'] = $userlogin;
    $_SESSION['role'] = $role;
    echo "<script>localStorage.setItem('login', '$user');
    window.location.href = 'indexforadmin.html';</script>";     
    }
    else
    {
        session_start();
        $_SESSION['id'] = $id;
        $_SESSION['password'] = $userpass;
        $_SESSION['login'] = $userlogin;
        $_SESSION['role'] = $role;
        echo "<script>localStorage.setItem('login', '$user');
        window.location.href = 'indexforuser.html';</script>";   
    }
    }
 else {
    header('Location: Login.html?message=Неверные+данные');
    echo "<script>window.location.href = 'Login.html';</script>";
}
// Закрытие соединения с базой данных
?>