Tell me how to configure authorization. Php I know basically, since I don’t work with it, but I need to implement this task. I would like that when clicking on the button authorization passes and goes to another page. I do not fully understand how to check the data in the database and compare it with user data and, if there is a coincidence, re-direct to another page. Did you go the right way? How can I solve my problem?
authdb.php
<?php
$dbname = "dictdb";
$username = "root";
$userpass = "";
$charset = "utf8";
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$userdata = [
    "logVal" => trim($_POST["logVal"]),
    "passVal" => trim($_POST["passVal"])
];
$db = new PDO("mysql:host=$dbhost;dbname = $dbname;charset=$charset", $username, $userpass, $options);
if (!empty(trim($_POST["logVal"])) && !empty(trim($_POST["passVal"]))) {
    $query = "SELECT * FROM  `dictdb`.`user` WHERE `login` = :logVal AND `password` = :passVal";
    $user_data = $query-fetchAll();
if ($user_data[password] == :passVal) {
echo "ok";
};
?>
auth.php
$(document).ready(function () {
    $("button.btn-auth").on("click", function () {
        $.ajax({
            url: '/src/php/auth.php',
            type: "POST",
        });
    });
});
 
    