2012-11-17 58 views
-1

我有一個名爲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 --> 
    &nbsp;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>"; 
?> 

我現在沒有收到任何錯誤信息,只是我沒有做任何事情在用戶名和密碼中單擊登錄。

+0

你做了什麼調試?你看過$ _POST數組中的數據,看看它在那裏嗎?您是否嘗試過在MySQL提示符下手動運行您的SQL查詢?你是否在PHP中啓用了所有的錯誤信息,並閱讀了錯誤日誌文件? –

+0

我還沒有真正做過任何調試,因爲我沒有收到任何錯誤消息。我的SQL查詢似乎在MySQL提示符下工作正常。 –

回答

0

嘗試loginProcess.php這個代碼

$username=$_POST['username']; 

$密碼= $ _ POST [ '密碼'];

+0

剛剛嘗試過。同樣的事情,沒有任何反應 –

+0

對用戶''@'localhost'拒絕表'用戶'的SELECT命令 我現在得到了那個錯誤。有任何想法嗎? 謝謝 –

+0

你確定你的mysql權限?您無需密碼即可與root連接。嘗試創建一個新用戶並賦予用戶對他的所有權利 –

0

我認爲你應該刪除 ob_start(); 從loginProcess.php文件的第一行開始,它在那裏沒有任何關係(除非告訴我很好的理由),它會阻止將數據發送到瀏覽器

+0

我刪除了ob_start(); - StackOverflow上的某個人告訴我昨天使用它。 我已將其刪除並將loginProcess.php中的代碼更改爲: $ username = $ _ POST ['username']; $ password = $ _ POST ['password']; 如上所示,但仍然沒有任何反應 –