我有一個登錄頁面。我確信數據庫已連接,但是當我提交表單時,頁面刷新並沒有任何反應。 我可以請知道這裏有什麼問題嗎?我似乎無法修復它。 =(我的登錄頁面似乎無法正常工作
<?php
session_start();
require_once('common/config.php');
if(isset($_POST['username']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM `users` WHERE username='$username' and password='$password'";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1)
{
$_SESSION['username'] = $username;
header("location: adminhomepage.php");
}
else
{
echo "Invalid Login Credentials.";
}
}
?>
這裏是我的形式。
<html>
<head>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<title>
XXX
</title>
<link rel="stylesheet" href="login.css">
</head>
<body>
<img id= "loginlogo" src="images/loginlogo.png" alt="XXX">
<h1 id = "loginmain">
XXX
</h1>
<br>
<div id= "inputs">
<form id ="loginform" action="login.php" method="post">
<h2 id = "loginheading">
LOGIN
</h2>
<hr id ="loginline">
<br>
<input id="username" type="text" placeholder="Username" autofocus required>
<br><br>
<input id="password" type="password" placeholder="Password" required>
<br><br>
<input id="loginbutton" type="submit" value="Login">
</form>
</div>
</body>
</html>
你是否在迴應$ count並查看它將要發生什麼? – Choco 2014-11-03 11:48:34
檢查密碼並在調用標題後添加一個'exit();' – Mihai 2014-11-03 11:51:57
如果表單有方法等於post method =「post」 – Eldar 2014-11-03 11:58:17