我有一個名爲admin(和密碼admin)的用戶的MySQL數據庫。我正在使用它來測試我的配置。當我點擊登錄時,沒有任何反應。任何人都可以看到我做錯了什麼嗎?Php會話登錄 - 沒有任何反應,爲什麼?
這裏是我的登錄表單:
<form action="loginProcess.php" method="POST">
Username: <input type='text' name='username'></br>
<!-- input type password makes the password hidden as it is typed -->
Password: <input type='password' name='password'></br>
<input type='submit' value='Login'/>
</form>
</br>
</br>
<!-- Register New User -->
<form action="register.php" method="POST"> </br>
Not Registered?<input type='submit' value='Click Here To Register'/>
</form>
這種形式把你帶到這個loginProcess.php文件:
<?php
ob_start();
session_start();
// Include database connection and select database UFPProducts
include "./shopdb/connection.php";
?>
<?php
//
// (2) Collect data from form and save in variables
// real escape string to protect from SQLi attacks
$username=mysql_real_escape_string(htmlentities($_POST['username']));
$password=mysql_real_escape_string(htmlentities($_POST['password']));
// (3) Create query of the form below to search the user table
// "SELECT * FROM Users WHERE UserName='$username' AND Password='$password'"
$query = "SELECT * FROM USERS where Username='$username' AND Password='$password'";
$result = mysql_query($query) or die (mysql_error());
// (3) Run query through connection
// (4) Check result of query using code below
// if rows found set authenticated user to the user name entered
if (mysql_num_rows($result) > 0) {
$_SESSION["authenticatedUser"] = $username;
// Relocate to the logged-in page
header("Location: ./login/loggedOn.php");
}
else
// login failed redirect back to login page with error message
{
$_SESSION["message"] = "Could not connect as $username " ;
header("Location: login.php");
}
?>
而這裏只是櫃面任何人希望看到我的connection.php文件:
<?php
//*** "die()" will exit the script and show an error if something goes wrong with the "connect" or "select" functions.
//*** A "mysql_connect()" error usually means your connection specific details are wrong
//*** A "mysql_select_db()" error usually means the database does not exist.
// Place db host name. Usually is "localhost" but sometimes a more direct string is needed
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "root";
// Place the password for the MySQL database here
$db_pass = "";
// Place the name for the MySQL database here
$db_name = "UFPProducts";
$connect = mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
mysql_select_db("$db_name") or die("there is no database with that name");
// echo "<center>You are successfully connected to the Under5Pounds database.</center><br>";
?>
我現在沒有收到任何錯誤信息,只是我沒有做任何事情在用戶名和密碼中單擊登錄。
你做了什麼調試?你看過$ _POST數組中的數據,看看它在那裏嗎?您是否嘗試過在MySQL提示符下手動運行您的SQL查詢?你是否在PHP中啓用了所有的錯誤信息,並閱讀了錯誤日誌文件? –
我還沒有真正做過任何調試,因爲我沒有收到任何錯誤消息。我的SQL查詢似乎在MySQL提示符下工作正常。 –