<?php
if(!isset($_COOKIE['id']))
{
    echo "<script>window.location.href = 'index.php';</script>";
}
else
{


session_start();
$host = "blueris.beget.tech";
$username = "blueris_base";
$password = "Qwer123.";
$database = "blueris_base";
$mysql = new mysqli($host, $username, $password, $database);

$pass = $_POST["password"];
if($mysql->connect_error){
    die("Ошибка подключения". $mysql->connect_error);
}


// Получение данных пользователя из базы данных
session_start();
if (isset ($pass ))
if (isset ($_COOKIE['id']))
$user_id = $_COOKIE['id'];
$userpass = $_SESSION['password'];
$quary = "SELECT * FROM login WHERE password like'$userpass'";
$result = mysqli_query($mysql, $quary);
if(mysqli_num_rows($result) > 0 && $userpass == $pass)
{
    header('Location: changepassword.php?message=Пароли+совпадают');
    echo "<script>window.location.href = 'changepassword.php';</script>";     
    mysqli_close();
    session_abort();
}
if($userpass != $pass)
{
$query = "UPDATE login SET password = '$pass' WHERE id_user = $user_id";
if($res = mysqli_query($mysql, $query))
{
    session_start();
    $_SESSION['password'] = $pass;
    echo "<script>window.location.href = 'Account.php';</script>";     
}
}
}
?>