PHP $ _POST得到未定义的索引,即使给出了输入

rma*_*234 1 php post

我试图使用$ _POST方法从HTML表单获取用户名和密码,但我得到一个未定义的索引错误与给定的输入.

我的索引文件的表单部分如下

<form class="form-signin"  role="form"action="" method="post">
        <h2 class="form-signin-heading">title<em class='current'>title</em></h2>
        <input id="username" type="username" class="form-control" placeholder="Username" required autofocus>
        <input id="password" type="password" class="form-control" placeholder="Password" required>
        <input name ="submit" type="submit" value="sign in">
      </form>
Run Code Online (Sandbox Code Playgroud)

我也有我的PHP脚本(称为auth.php)包含在我的索引文件的顶部.

这是我的auth.php脚本代码示例

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "auth is called";
if(isset($_POST['submit'])){
echo "submit is pressed";
//this if statement enters when submit is pressed
if(empty($_POST['username']) || empty($_POST['password'])) {
echo "Username or Password is empty";
//this if statement enters too, even with input given
}
else{
echo "YAY";
}
}
?>
Run Code Online (Sandbox Code Playgroud)

即使我在输入字段中输入用户名和密码,"用户名或密码为空"语句也会继续打印.问题是什么

Dim*_*rab 5

缺少"名称" attribute in input字段,应该是

编辑2:用户名中缺少type ="text"input

 <input type="text" name='username' id="username" class="form-control" placeholder="Username" required autofocus>
 <input name='password' id="password" type="password" class="form-control" placeholder="Password" required>
Run Code Online (Sandbox Code Playgroud)