首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >致命错误:在非对象上调用成员函数bind_param()

致命错误:在非对象上调用成员函数bind_param()
EN

Stack Overflow用户
提问于 2013-12-28 18:57:05
回答 2查看 127关注 0票数 0

失败的bind_param是这样的

$stmt->绑定参数(‘sss’,$this->模板->表单->注册表用户名,$this->模板->表单->注册表密码,$this->模板->表单->reg_email,“测试”);

准备好的语句是

$stmt = $this->mysqli->prepare("INSERT INTO 'users‘(username,password,email,referr) VALUES (?,?)");

整个注册函数是

public function Register() {

    unset($this->template->forms->error);
    $this->template->forms->setData();

    if(isset($this->template->forms->submit)) {

        if(!isset($this->template->forms->reg_username)) {
            $this->template->forms->error = "You must enter an username";
        }

        if(!isset($this->template->forms->reg_password)) {
            $this->template->forms->error = "You must enter a password";
        }

        if(!isset($this->template->forms->reg_password_confirm)) {
            $this->template->forms->error = "You must confirm your password";
        }

        if(!isset($this->template->forms->reg_email)) {
            $this->template->forms->error = "You must enter an email address";
        }

        if($this->template->forms->reg_password != $this->template->forms->reg_password_confirm) {
            $this->template->forms->error = "Your passwords must match";
        } else if(strlen($this->template->forms->reg_password) <= 5) {
            $this->template->forms->error = "Your password must be 6 characters or more.";
        }

        if(!$this->template->forms->error) {
            $stmt = $this->mysqli->prepare("INSERT INTO 'users' (username, password, email, referr) VALUES (?, ?, ?, ?)");
            $stmt->bind_param('ssss', $this->template->forms->reg_username, $this->template->forms->reg_password, $this->template->forms->reg_email, "Adam");
            $stmt->execute();
        }

    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-12-28 22:31:54

您的MySQL查询中存在错误。如果无法创建预准备语句,则prepare()方法将返回false。来自prepare()方法的文档:

返回值

如果发生错误,mysqli_prepare()将返回一个statement对象或FALSE

错误消息将存储在MySQLi连接对象的error field中。在尝试发送查询或创建预准备语句时,请始终添加错误处理。

票数 1
EN

Stack Overflow用户

发布于 2018-07-10 04:03:21

我相信你的SQL中有一个错误,@Progman在他的回答中指出了这一点。我认为错误是你有‘用户’,而它应该是users,这可能会导致它失败。将您的SQL更改为我在下面提供的SQL,并让我知道它是否有效。

INSERT INTO `users` (username, password, email, referr) VALUES (?, ?, ?, ?)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20813722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档