lundi 5 avril 2021

Why doesn't PHP set value to variable? [closed]

Code:

if($_SERVER["REQUEST_METHOD"] == "POST"){
    $username = $_POST["username"];
    $password = $_POST["password"];

    $errorz = false;

    if(empty(trim($_POST["username"]))){
        $errorTxt = "Имя Пользователя или Пароль неправильны!";
        $errorz = true;
    } else{
        $username = trim($_POST["username"]);
    }

    if(empty(trim($_POST["password"]))){
        $errorTxt = "Имя Пользователя или Пароль неправильны!";
        $errorz = true;
    } else{
        $password = trim($_POST["password"]);
    }
        
    if (empty($errorTxt)) {
        $res1 = mysqli_query($connection, "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'");

        if ($res1 == FALSE) {
            $errorTxt = "Имя Пользователя или Пароль неправильны!";
            $errorz = true;
        } elseif ($res1 == TRUE) {
            session_start();
    
            $_SESSION["loggedin"] = true;
            $_SESSION["id"] = $id;
            $_SESSION["username"] = $username;  
    
            header("location: index.php");
        }
    }
    
    if ($errorz == true) {
        $errorTxt = "Имя Пользователя или Пароль неправильны!";
    }

And here is the one part in HTML body that we'll need: <h4 id="logErrText"><?php echo $errorTxt;?></h4>.

P.S: Имя Пользователя или Пароль неправильны! means Username or Password is incorrect!

So what's the problem you would ask? Well, when you press Log In button, whenever the username/pass is not right, it should display that "Username or Password is incorrect!" as a content of the paragraph with the id = "logErrText" (see in the code block above). But it does not.

Help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire