使用 PHP 登录并注册,登录时提示密码无效

Made a login and registration with PHP, login says password not valid

<?php
require_once "config.php";
require_once "session.php";
$error = '';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
    $email = trim($_POST['email']);
    $password = trim($_POST['password']);
    // validate if email is empty
    if (empty($email)) {
        $error .= '<p class="error">Please enter an email.</p>';
    }
    // validate if password is empty
    if (empty($password)) {
        $error .= '<p class="error">Please enter your password.</p>';
    }
    if (empty($error)) {
        if($query = $db->prepare("SELECT * FROM users WHERE email = ?")) {
            $query->bind_param('s', $email);
            $query->execute();
            $row = $query->fetch();
            if ($row) {
                if (password_verify($password, isset($row['password']))) {
                    $_SESSION["userid"] = $row['id'];
                    
                    // redirect the user to the welcome page
                    header("location: index.php");
                    exit;
                } else {
                    $error .= '<p class="error">The password is not valid.</p>';
                }
            } else {
                $error .= '<p class="error">No user exists by that email address.</p>';
            }
        }
        $query->close();
    }
    // close connection
    mysqli_close($db);
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Login</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    </head>
    <body>
        <div class="container">
            <div class="row">
                
               
                <form action="" method="post">
                   <h2>Login</h2>
                     <?php echo $error; ?>
                       <div class="form-group">
                        <label>Email Address</label>
                        <input type="email" name="email" class="form-control" required />
                    </div>
                    <div class="form-group">
                    <label>Password</label>
                    <input type="password" name="password" class="form-control" required />
                    </div>
                    <div class="form-group">
                    <input type="submit" name="submit" class="btn btn-primary" value="submit">
                    </div>
                </form>
            </div>
        </div>
    </body>
</html>

我有很多错误,比如 if (password_verify($password, $row['password'])) 说:

Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\defgonnawork\login.php on line 22

但我只是在那里扔了一个 isset 数据库已正确连接,使用电子邮件和密码注册成功,我可以看到它已保存在数据库中。

您没有得到结果。试试这个

$result = $query->get_result();

/* now you can fetch the results into an array */

if($row = $result->fetch_assoc()){

    //rest of the code

}