我試着做一個登錄表單。當點擊提交按鈕時重定向到其他頁面
我想在用戶點擊提交按鈕後在同一頁上顯示錯誤消息。
如果用戶使用正確的信息登錄系統,它應該轉到索引頁面。
這是我寫的代碼,但它不起作用 - 它每次都會進入相同的頁面。
<?php
if (isset($_POST['login'])) {
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$query = mysql_query("select *from user where username='$uname'") or die(mysql_error());
$numrows = mysql_num_rows($query);
if ($numrows != 0) {
while ($row = mysql_fetch_assoc($query)) {
$dbuname = $row['username'];
$dbpassword = $row['password'];
$status = $row['status'];
}
if ($status == 0) {
?>
<div class="alert alert-danger" style="text-align: center ; font-size: 17px;" role="alert">Your account is not yet activated.Please check your email to activate account.</div>
<?php
} else if ($uname == $dbuname && $pass == $dbpassword) {
$_SESSION['username'] = $uname;
header('Location: index.php');
?>
<?php
} else {
?>
<div class="alert alert-danger" style="text-align: center ; font-size: 17px;" role="alert">Incorrect Password.</div>
<?php
}
} else {
?>
<div class="alert alert-danger" style="text-align: center ; font-size: 17px;" role="alert">Incorrect Username.</div>
<?php
}
}
?>
<form name="add" action="login-jobseeker.php" method="post" enctype="multipart/form-data" >
<table class="table ">
<tr>
<td>Username</td>
<td>
<input type="text" required name="uname" class="form-control col-lg-12 " placeholder="Title">
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" required name="pass" class="form-control col-lg-12 " placeholder="Name">
</td>
</tr>
<tr>
<td></td>
<td>
<a href="register.php?type=<?php echo $type ?>" >Register for a free account</a>
</td>
</tr>
<tr>
<td></td>
<td>
<a href="forget.php" >Forget Password??</a>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="login" class="btn btn-primary" value="Login">
</td>
</tr>
</table>
</form>
如何解決此問題?
感謝您的回覆。是的,我想重定向到同一頁面,如果有任何error.error應顯示在同一頁面上。但如果登錄成功,它應該重定向到索引頁 – user5008468
嘗試添加此代碼的末尾: header('Location :nextpage.php'); – user3106974