HTML 表单验证 PHP

HTML form Validation With PHP

我尝试了一个简单的 html 表单登录,但该表单没有响应。 我是 PHP 编程新手。

请帮忙

<?php
$match = 'honey';

if (isset($user_name) && isset($password)) {
    $user_name = $_POST['user_name'];
    $password = $_POST['password'];
    $submit = $_POST['submit'];

    if (!empty($user_name) && !empty($password)) {
        if ($password == $match) {
            echo 'Logged in';
        } else
            echo 'Incorrect password or username';
    } else
        echo 'Please fill in all the fields';


}

?>

<form action="index.php" method="POST">
Username:<input type="text" name="user_name" /><br><br>
Password:<input type ="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>

您正在使用 isset() 作为您尚未声明的变量。

改变你的

if (isset($user_name) && isset($password))

if (isset($_POST['user_name']) && isset($_POST['password'])

usernamepassword 未定义

应该是

if(isset($_POST['user_name') && isset($_POST['password'])){

 $user_name = $_POST['user_name'];
$password = $_POST['password'];
$submit = $_POST['submit'];

if (!empty($user_name) && !empty($password)) {
    if ($password == $match) {
        echo 'Logged in';
    } else
        echo 'Incorrect password or username';
} else
    echo 'Please fill in all the fields';

}