php
  • mysql
  • 2013-10-16 39 views 0 likes 
    0

    我開發了一個用於登錄的登錄表單,但是當我嘗試登錄時它無法通過。以下是我使用的代碼的一部分。當我回顯$num時,具有$num = mysql_num_rows()的部分將返回零。這是爲什麼?看來我的INSERT查詢沒有返回結果。請幫忙。用於登錄的MySql查詢不起作用

    if ($warning==''){ 
         $query="SELECT first_name FROM tblusers WHERE (email='$username') AND (password='".md5($_POST['password'])."')"; 
         [email protected]_query($query); 
         $num = mysql_num_rows($result); 
         @mysql_close(); 
         echo $num."perfecto".$result;   
         if($num==1) 
         { 
          $u=new User($username); 
          include ('includes/highlight.inc.php'); 
          //insert user into session 
          if ($username=='admin'){ 
           $_SESSION['user']=$username; 
           $p=new Page('Log In'.$username); 
           $p->setHeading('Welcome '.$u->getFirstName()); 
           $p->setContent($cont."<br/><br/><br/> Use the administrator's panel on the right to do the administration work of the 
               website. To block and unblock users you use the <font color=red><b>View Auctions</b></font> link, and 
               that is when you can block the user after assessing their record."); 
           $p->printIt(); 
          } else { 
          $_SESSION['user']=$username; 
          $p=new Page('Log In'.$username); 
          $p->setHeading('Welcome '.$u->getFirstName()); 
          $p->setContent($cont."<br/><br/><br/>".$text); 
          $p->printIt(); } 
    
         } 
    
    +0

    檢查手冊查詢 –

    +0

    你可以試試這個:SELECT first_name FROM tblusers WHERE email ='$ username'AND password ='md5($ _ POST ['password'])'作爲查詢 – Satya

    +0

    執行'var_dump($ query );'在'SELECT'行下面,並將包含的變量與數據庫中的值進行比較。除此之外(與您的問題無關,mysql擴展在PHP 5.5.0以前不推薦使用,並且將來會被刪除,相反,應該使用MySQLi或PDO_MySQL擴展 – Bjoern

    回答

    0

    改變你的查詢字符串:

    $query="SELECT first_name FROM tblusers WHERE email='".$username."' AND password='".md5($_POST['password'])."'"; 
    

    ,並檢查使用echo $query,以確保它是正確的查詢字符串

    0

    如下更改您的查詢字符串:

    $password = md5($_POST['password']); 
    $query = "SELECT first_name FROM tblusers WHERE email='".$username."' AND password = '".$password."'"; 
    

    希望這可以幫助你。

    +0

    非常感謝。問題是MD5對於相同的密碼導致了不同的結果,所以我無法登錄。不知道該怎麼用,因爲即使sha1也拒絕工作 – Kriz

    相關問題