我有2个文本字段,用户名和密码。当我输入密码时,它会跳转到第一个密码。我不知道为什么会这样。我无法找到它跳跃的原因。如何更改它以便密码表单不会跳转?这是代码:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
答案 0 :(得分:3)
您将两个输入都包装在一个标签中。浏览器变得混乱,它认为整个内容是第一个输入的标签(这就是标签的工作方式,显然)。您应该只使用<label>
来包装文本以进行输入。
答案 1 :(得分:2)
这:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
应该是这样的:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />