<?php
$user_name = "";
if (isset($_POST["login"])) {
    //dane w formularzu zostały podane
    $user_name = "'" . htmlspecialchars($_POST['user_name']) . "'";
    $password = htmlspecialchars($_POST['password']);

    if (!empty($user_name) && !empty($password)) {
        //przeczytaj z bazy danych
        $query = "select * from users where name = $user_name limit 1";
        $result = mysqli_query($con, $query);

        if ($result) {
            if ($result && mysqli_num_rows($result) > 0) {

                $user_data = mysqli_fetch_assoc($result);

                if (password_verify($password, $user_data['password'])) {

                    $_SESSION['user_id'] = $user_data['user_id'];
                    $id =  "'" . $user_data['user_id'] . "'";
                    mysqli_query($con, "UPDATE `users` SET `active`='1' WHERE `user_id` =$id");
                    header("Location: ../admin/paneluser.php");
                    exit();
                }
            }
        }

        echo "<script type='text/javascript' >alert('błędny username lub password!');window.location = '../login/login.php';</script> ";
    } else {
        echo "<script type='text/javascript' >alert('pola nie mogą być pustę');window.location = '../login/login.php';</script> ";
    }
}
