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

时间:2014-06-17 18:18:45

标签: php mysqli

include "Forum.php";
 var_dump($_POST);
 class db_Forum{
     public $db_conn;

    function __construct(){
        $this->db_conn = new mysqli("localhost","root","","forums");

        if(mysqli_connect_error()){
        echo ("Database connect error:".mysqli_connect_error());
        }
    }   

    public function connect(){
        return $this->db_conn;
    }

    public function insert_question(){

        $query = "INSERT INTO forums.question_table VALUES (?, ?)";
        $forums= new Forum();
        $stmt= $this->db_conn->prepare($query);
        $stmt->bind_param(ss,$_POST['question'],$_POST['description']);
        $stmt->execute();
        if($stmt->execute()){
        return true;
        }
        else{
        return false;
        }
    }


}

我正在尝试面向对象的PHP,并且收到此错误“致命错误:在C:\ xampp \ htdocs \ PHP \ PHP_project \ PHPforums \ db_forum.php上的非对象上调用成员函数bind_param() 24" Forum.php-包含一个论坛类。以下是论坛类的代码:

<?php

 class Forum{
    public $question;
    public $description;
    public $answer;

}

?>

1 个答案:

答案 0 :(得分:2)

$stmt不是对象。这是因为之前的错误。检查您的语句是否已成功创建。也许您的查询中有错误。

输出错误将有助于您:

echo $this->db_conn->error;

请参阅http://php.net/manual/de/mysqli.error.php