登录失败后,我试图重定向到同一页面,但我被重定向到。/login.php这是我的代码:Index.php:
<body>
<h1><strong>Login</strong></h1>
<form action="login.php" method="POST">
<table id="mytable">
<tr>
<td><select name="type">
<option value="Admin">Admin</option>
<option vale="User">User</option>
</select></td>
</tr>
<tr>
<td><input type="text" name="username" placeholder="Username"><br><br> </td>
</tr>
<tr>
<td><input type="password" name="password" placeholder="Password"><br><br> </td>
</tr>
<tr>
<td><input type="submit" value="Login" ><br><br> </td>
</tr>
</table>
</form>
</form>
</body>
</html>
登录.php:
?php
require 'ceva.php';
$type=$_POST['type'];
$username=$_POST['username'];
$password=$_POST['password'];
//if(!empty($username) && !empty($password))
//{
$sql= "SELECT * FROM login WHERE username ='$username' and password='$password' and type='$type'"; // selecteaza din baza de date login
$rezultat= mysqli_query($con, $sql);
while($rand=$rezultat->fetch_assoc())
{
if($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'Admin') //verificare array
{
header("Location: admin.php"); //muta in pagina admin.php
}else if ($rand['username'] == $username && $rand['password'] == $password && $rand['type'] == 'User'){
header("Location: user.php");
}else {
header("Location: index.php");
}
}
如果凭据正确,我将被重定向到user.php或admin.php很好,但如果它们是错误的,我应该被重定向到index.php
翻翻过去那场雪