php - mysqli - fatal error

标签 php mysql mysqli mysql-error-1064

我的代码中有一个 fatal error , fatal error :第 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();

    }


?>

有人可以检查一下代码吗?我的想法是。我有一个功能,如果有效,请发送电子邮件。可能我的代码有一些错误

谢谢!!

最佳答案

您调用 check() 时使用的参数太少。

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

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

关于php - mysqli - fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5380144/

相关文章:

mysql - 在 mysql 中聚合和计算值

带有 'flexible' WHERE 子句和 % 匹配的 Mysql 请求

php - 在生产中使用 mysqli_connect() 从 Mysql 选择行时出现问题

php - 使用PHP从HTML表单向MySQL插入数据报错

php - 如何在wordpress自定义导航中显示子项

PHP mail() 函数服务器和本地主机不工作

php - 如果表 1 中存在值,则插入表 2 mysql

php - 防止在 div 中形成新行

php - PDO::query() 期望参数 1 为字符串,对象给出警告

PHP 不会解析完整的 JSON 文件以获得所有结果