我的代码中有致命错误,致命错误:在第28行的某个非对象上调用成员函数prepare()
更新代码:
<?
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 :(得分:2)
您使用一个参数调用check()
太少了。
function check($sql, $db, $email, $pwdHasher, $hash, $userExists, $sendPass ) {
^------------ Missing
check($sql, $email, $email,$pwdHasher, $hash, $userExists, $sendPass
答案 1 :(得分:0)
从错误中可以清楚地看出,$db
不是对象,也不是具有数据库连接的对象,可以调用mysqli函数。
请检查并确保您在函数中传递了正确的对象,并且忘记传递该对象。