我有一个页面(index.php)是一个登录页面,所以我需要验证用户并重定向到其他页面,但 header(Location:"welcome.php"); 不工作,sql 查询没问题,但我只收到消息“登录成功”并且页面不会重定向到另一个名为welcome.php 我是 PHP 新手,所以任何帮助都很棒!
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.ico">
<title>Login</title>
<link href="bootstrap.min.css" rel="stylesheet">
<link href="signin.css" rel="stylesheet">
</head>
<body>
<div class="container">
<form class="form-signin" role="form" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<h2 class="form-signin-heading"><center>Bienvenido!</center></h2>
<input type="text" name="username" class="form-control" placeholder="Username" required="" autofocus="">
<input type="password" name="password" class="form-control" placeholder="Password" required="">
<div class="checkbox">
<label><input type="checkbox" value="remember-me"> Remember me </label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
</form>
</div>
<?php
$link = mysqli_connect("localhost","root","root","testdb") or die ("error".mysqli_error($link));
$username = $_POST['username'];
$password= $_POST['password'];
if (isset($_POST['username'])) {
$sql = "SELECT * FROM testdb.user WHERE username='$username' and password='$password'";
$result = mysqli_query($link,$sql);
if ($result);
{
$num=mysqli_num_rows($resultado);
}
if($num==1)
{
header("Location: welcome.php");
exit();
}else{
header("Location:wrong.php");
}
mysqli_free_result($result);
mysqli_close();
}
?>