2012-09-13 28 views
0

我有mysql連接及其工作。連接完成,MySQL結果可以。我試圖登錄我的面板,但每次給「密碼不正確」/Kullanıcıadınızveyaşifrenizyanlış。我怎樣才能解決這個問題?Mysql和PHP結果很好,但登錄不正確

if(@$_GET['selection'] == 'verification') 
    { 
     $myusername=$_POST['myusername']; 
     $mypassword=$_POST['mypassword']; 
     $tbl_name="kullanicilar"; 
     $myusername = stripslashes($myusername); 
     $mypassword = stripslashes($mypassword); 
     $myusername = mysql_real_escape_string($myusername); 
     $mypassword = mysql_real_escape_string($mypassword); 

     $sql="SELECT * FROM kullanicilar WHERE kullaniciadi='$myusername' and sifre='$mypassword'"; 
     [email protected]_query($sql); 
     [email protected]_num_rows($result); 
     if (@mysql_num_rows($result) != 0) 
     { 
      session_register("myusername"); 
      session_register("mypassword"); 
      header("location:index.php?page=giris&lang=tr&selection=verified"); 
     } 
     else 
     { 
      echo "Kullanici adiniz veya sifreniz yanlis. <b>$count</b>"; 
     } 
    } 
+0

請不要在新代碼中使用'mysql_ *'函數。他們不再被維護,社區已經開始[棄用流程](http://news.php.net/php.internals/53799)。看到[**紅框**](http://php.net/mysql-connect)?相反,您應該瞭解[準備好的陳述](http://en.wikipedia.org/wiki/Prepared_statement)並使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysqli)。如果你不能決定,試試[這篇文章](http://php.net/mysqlinfo.api.choosing)。如果你關心學習,[這裏是很好的PDO教程](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)。 –

+2

你是否以明文存儲你的密碼?爲我們提供數據庫結構和html表單結構 – rsz

+0

刪除@並查看是否生成錯誤,可能會給你更多的信息。你可能也想在沒有WHERE子句的情況下從表中進行選擇,並遍歷比較結果,一路輸出結果......可能你只是不匹配字符串。 – Dave

回答

0

你需要做幾件事情:

  1. 使用$計數的「如果」條件,而不是再次調用mysql_num_rows功能。每個mysql函數調用都是你想要避免的開銷。

  2. 嘗試通過評論「stripslashes」行代碼。

  3. 回聲並獲取查詢。然後直接運行查詢而不使用這個腳本(就像在SQLYog或phpMyAdmin中一樣),看看它是否會給你結果。