我試圖在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