所以我有這個驗證碼。除了輸入錯誤的用戶名時,其他所有功能都可以使用。它只是一直顯示在頁面中:「無法運行查詢:」< - 僅此。我不知道什麼是錯的。請幫忙。無法運行查詢:??沒有查詢錯誤消息導致我無處可以
這裏是我的那部分代碼:
if($UserN){
if($UserP){
require("connect.php");
$query = mysql_query("SELECT * FROM customer WHERE UserName = '$UserN'");
$numrows = mysql_num_rows($query) or die ('Unable to run query:'.mysql_error());
if($numrows == 1){
$row = mysql_fetch_assoc($query)or die ('Unable to run query:'.mysql_error()); // fetch associated: get function from a query for a database
$dbpass = $row['PassWord']; // read password of inputted user from the query.
$dbuser = $row['UserName']; // read username from the query
$dbactive = $row['Active']; // read if user is active
$dbid = $row['CustNum'];
if($UserP == $dbpass){
if($dbactive == 1){
//set session information
$_SESSION['CustNum'] = $dbid;
$_SESSION['UserName'] = $dbuser;
echo "<br><br><center><b>You have been logged in as <b>$dbuser</b>. <a href='orderform.php'>Click here</a> to go to the member page.</b></center><br><br>";
}
else
echo "$form <center><b>You need to activate your account.</b></center></br>";
}
else
echo "$form <center><b>You did not enter a correct password.</b></center> </br>";
}
else
echo "$form <center><b>The username you entered was not found.</b></center></br> ";
mysql_close();
}
else
echo "$form <center><b>You must enter your password. </b></center></br>";
}
else
echo "$form <center><b>You must enter your username. </b></center></br>";
您的代碼很容易受到SQL注入的位置:'的mysql_query( 「SELECT * FROM客戶其中username = '$用戶N'」);' –
更好的希望Little Bobby Tables永遠不會嘗試登錄。 –
這是非常不安全的,不應該暴露給公衆。一個[自動SQL漏洞測試工具](http://sqlmap.org/)將有一個與此相關的現場日。如果你有這樣的代碼,只是被黑客攻擊纔是時間問題。 – tadman