i have a fatal error in my code, Fatal error: Call to a member function prepare() on a non-object in ... on line 28
Updated code:
<?
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> &开发者_开发技巧lt;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();
}
?>
can someone check the code? my idea is. I have a function and if is valid send the email. Probably i have some error in the code
thanks!!
You are calling check()
with one parameter too few.
function check($sql, $db, $email, $pwdHasher, $hash, $userExists, $sendPass ) {
^------------ Missing
check($sql, $email, $email,$pwdHasher, $hash, $userExists, $sendPass
It is clear from the error that your $db
is not the object and also not the object which have the connection for database and can call mysqli function.
Please check and make sure you are passing the correct object in the function and you are forgetting to pass that object.
精彩评论