我在凭据正确时创建了一个登录表单,它将转到另一个页面,但它会显示一个空页面。
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT username as username, password as password
from tbl_users
where user_type ='system admin'";
$result= sqlsrv_query($db,$query);
while ($user=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$uname = $user['username'];
$pwd = $user['password'];
}
// $url = 'http://localhost/chart/e/home.php';
if ($username == $uname && $password == $pwd ) {
header('Location : http://localhost/chart/e/home.php');
exit;
}
else{
echo "<script> alert('error') </script>";
}
}
这是表格
<form method="POST">
<input type="text" class="text" placeholder ="username" name="username">
<input type="password" placeholder ="password" name="password">
<input type="submit" name="login" value="Sign in">
</form>
答案 0 :(得分:0)
删除标题字段(Location
)和冒号(:
)之间的空格:
header('Location: http://localhost/chart/e/home.php');
每个标题字段由名称后跟冒号(“:”)和字段值组成。字段名称不区分大小写。字段值可以在任何数量的LWS之前,但优选单个SP。
供参考,见:
答案 1 :(得分:-1)
if(($ username == $ uname)&amp;&amp;($ password == $ pwd)){$ url =“http://localhost/chart/e/home.php”; 标题('Location:'。$ url);退出; }