2011-03-21 47 views
0

我有一個致命的錯誤在我的代碼,致命錯誤:調用一個成員函數準備()一個非對象在...上線28的mysqli - 致命錯誤

更新代碼:

<? 
function check($sql, $db, $email, $pwdHasher, $hash, $userExists, $sendPass) { 
    if(!empty($_POST['email']) && validateEmail($email)) { 
     $email = $_POST["email"]; 
     if ($sql = $db->prepare("select email from users where email=?")) { 

      $sql->bind_param('s', $email); 

      $sql->execute(); 

      $sql->bind_result($email); 

      while ($sql->fetch()) { 

       $pwdHasher = new PasswordHash(8, FALSE); 

       $hash = $pwdHasher->HashPassword($userExists["email"]); 

       $sendPass=$hash; 

       ($sql = $db->prepare('insert into password_reset (code) values (?)')); Warning: mysqli::prepare() [mysqli.prepare]: All data must be fetched before a new statement prepare takes place 
       $sql->bind_param('s', $hash); //Fatal error: Call to a member function bind_param() on a non-object 

       $sql->execute(); 
       $sql->fetch(); 

      } 
     } 
    } 
} 

    if (check($sql, $db, $email, $email,$pwdHasher, $hash, $userExists, $sendPass)) { 
     ($sql = $db->prepare("select userid from password_reset where code=?")); 
     $sql->bind_param('s', $hash); 
     $sql->execute(); 
     $sql->bind_result($hash); 

     if ($sql->fetch()) { 
      echo $hash; 

     }; 

     $pwrurl = "www.yoursite.com/reset_password.php?userid=" .$hash . "&code =" . $sendPass; 

     $mailbody = "Dear user,<br><br>If this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com<br> 
      To reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.<br> <a href='$pwrurl'>$pwrurl</a> <br> <br> 
      Thanks,\nThe Administration"; 

     $mail->MsgHTML($mailbody); 

     $mail->AddAddress($email,"Membro"); 

     $mail->IsHTML(true); 

     if(!$mail->Send()) { 
      echo "Deu erro: " . $mail->ErrorInfo; 
     } else { 
      echo "Enviado com sucesso"; 
     } 


     $sql->close(); 
     $db->close(); 

    } 


?> 

有人可以檢查代碼嗎?我的想法是。我有一個功能,如果有效發送電子郵件。可能我在代碼中有一些錯誤

謝謝!!

+0

您是否在同一時間出現PHP致命錯誤**和** SQL錯誤? – 2011-03-21 15:52:23

+0

$ db是與數據庫的連接 – 2011-03-21 15:53:48

回答

2

你打電話check()與一個參數太少。

function check($sql, $db, $email, $pwdHasher, $hash, $userExists, $sendPass) { 
         ^------------ Missing 

check($sql, $email, $email,$pwdHasher, $hash, $userExists, $sendPass 
+0

是的,你是正確的,我更新我的代碼。現在我得到新的問題,因爲我沒有完成第二個之前的第一個聲明。 – 2011-03-21 15:59:55

+0

我將查詢的代碼塊分開,現在可以正常工作,謝謝 – 2011-03-21 16:23:25

0

這是從你的$db不是對象,也不具有對數據庫的連接,可以調用mysqli的函數對象錯誤清除。

請檢查並確保您在函數中傳遞正確的對象,並忘記傳遞該對象。

+0

感謝Shakti。問題是我忘記了參數$ db,無論如何,現在我得到新的錯誤... :)。更新的代碼 – 2011-03-21 16:03:29