回声功能不显示


Echo function does not display

我尝试使用echo函数验证表单值,但它不起作用——它没有像我期望的那样显示在顶部。你能帮我吗。这是php代码:

<?php
if(isset($_POST['Submit']))
{
    $username=isset($_POST["username"]);
    $password=isset($_POST["password"]);
    echo "your name is".$username."and your password is ".$password;
}
?>

表单html代码为:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="form.php" methode="post">
        <input type="text" name="username" placeholder="enter your name">
        <input type="password" name="password" placeholder="enter your password"/><br>
        <input type="Submit" name="Submit"/>
    </form>
</body>
</html>

使用isset检查您指定的东西是否有值。在这种情况下,$_POST超级全局中的"username"索引。所以写作$username = isset($_POST["username"])返回的是布尔值,而不是您尝试的字符串值。如果您想要$_POST['username']的字符串值,请在isset周围使用三进制,如下所示:

$username = (isset($_POST['username']) ? $_POST['username'] : 'Some flavor of not set error';

在表单中,方法属性被错误地拼写为末尾的"e"。一旦你把它改为"方法",你的帖子就应该开始工作了。