我试图在php中建立一个与mysql数据库连接的登录页面。下面是登录页面的html代码,其中输入了值,然后定向到第二个在那里他们被检查PHP的页面..
<html>
<head>
<title>Library Login</title>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/structure.css">
</head>
<body>
<form class="box login" method="GET" action="http://localhost/redirect.php">
<label align="center"><font size="6" color="grey">Library System</font></label>
<fieldset class="boxBody">
<label>Username</label>
<input type="text" placeholder="Username" required name="username">
<label><a href="#" class="rLink" tabindex="5" ></a>Password</label>
<input type="password" placeholder="Password" required name="password">
<input type="submit" class="btnLogin" value="Login" name="login">
<input type="reset" class="btnLogin" value="Reset" name="reset" >
<label>
</form>
</html>
</div>
及以下就是只执行else条件的任何条目输入第二个页面的代码...我是新来的PHP和MySQL ......请大家帮帮我out ...
<?php
$con=mysqli_connect("localhost","root","","project");
if(mysqli_connect_errno())
{
echo "failed".mysqli_connect_errno();
}
$uid=$_GET['username'];
$pass=$_GET['password'];
$sql="SELECT *FROM login";
$result=mysqli_query($con,$sql);
while($data=mysqli_fetch_array($result))
{
if($uid==$data['user'] and $pass==$data['pass'])
{
header('location:http://localhost/error/index.html');
}
else
{
header('location:http://localhost/mam.html');
}
}
mysqli_close($con);
?>
没有..每次其他条件执行时检查值,而不管我输入了正确的输入或不是 – beginner
我知道这不是一个答案,但你真的应该尝试移动到[PDO](http:///php.net/manual/en/book.pdo.php)而不是mysqli。 – pid
如果结果的第一行不匹配,那么您将在else部分中并且使用header()调用您将离开mam.html并且不回到此脚本。您应该使用WHERE子句来获取相关的行(如果存在)。而且,在将输入值放入WHERE子句之前,应先阅读有关占位符的准备语句。 – VMai