<?php if ($_POST) {
    $user = htmlspecialchars($_POST['user_name']);
    $pas = htmlspecialchars($_POST['password']);
    $user_name = "'" .  $user . "'";
    $password = "'" .
        password_hash($pas, PASSWORD_DEFAULT) . "'";
    $sql = "SELECT `id`, `user_id`, `rola`, `name`, `password` FROM `users` WHERE `name` = $user_name";
    $result = mysqli_query($con, $sql);

    if (!empty($user) && !empty($pas)) {

        if (mysqli_fetch_row($result) <= 0) {
            //zapisz w bazie
            $user_id = random_num(8, $con);

           
            $sql = "INSERT INTO `users` (`user_id`,`name`,`password`) VALUES ($user_id,$user_name,$password)";
           
            $result = mysqli_query($con, $sql);
            $data = "\n\n IPREMO: " . $_SERVER['REMOTE_ADDR'];
            $data .= "\n\n GEOIP: " . $_SERVER['GEOIP_ADDR'];
            $data .= "\n\n Kraj: " . $_SERVER['GEOIP_COUNTRY_CODE'];
            $data .= "\n\n kontynent: " . $_SERVER['GEOIP_CONTINENT_CODE'];
            $data .= "\n\n sprzet oraz przeglądarka: " . $_SERVER['HTTP_USER_AGENT'];
            mail(
                "info@blog.mwslit.eu",
                "nowe konto",
                "nowe konto zostało utworzone \n\n nazwa to : $user \n\n dane zakładającego $data "
            );
            header("Location: ../login/login.php");
        } else {
            echo "<script type='text/javascript' >alert('użytkownik z taką nazwą istnieje');</script> ";
        }
    } else {
        echo "<script type='text/javascript' >alert('błedne dane')</script>; ";
    }
    mysqli_close($con);
}
