我正在制作一个带有嵌入式输入表格的导航栏,但登录按钮时没有设置用户名和密码的值。我陷入了困境,我无法弄清楚为什么会这样?
<div class="navbar-fixed">
<nav>
<div class="nav-wrapper black darken-2 z-depth-4 navbar-fixed">
<a href="#!" class="brand-logo">   $~ CodersArena</a>
<ul class="right hide-on-med-and-down " >
<?php
include('includes/bootstrap.php');
$con = dbConnect();
if (isset($_POST['username']) && isset($_POST['password'])){
$username =$_POST['username'];
$password = $_POST['password'];
$sql = "SELECT username FROM users WHERE username='" . $username . "' AND password='" . $password . "'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
echo"success";
$_SESSION['username'] = $username;
echo '<li>
<span class="white-text white">';
echo $_SESSION['username'];
echo '</span>
</li>';
}
}
else
{
if (!isset($_SESSION['username'])) {
echo '
<form action="index.php" method="POST" >
<li style="padding: 20px auto; margin-right:10px ">
<input id="username" type="text" class="validate" style="height:30px" autocomplete="off" placeholder="Username">
</li>   
<li style="padding: 20px auto; margin-right:10px ">
<input id="password" type="text" style="height:30px" autocomplete="off" placeholder="Password">
</li>
<button style="padding: 20px auto; margin:10px " type="submit" class="btn-flat indigo darken-1 white-text right">Login</button>
</form>';
}
}
?>
</ul>
</nav>
答案 0 :(得分:5)
您的<input>
缺少name="username"
和name="password"
属性,这些属性将进入POST请求。
任何没有name
的输入都不会包含在表单提交中。