douchengchen7959 2014-06-17 18:18
浏览 41

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

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;
        }
    }


}

I am trying object oriented PHP, and getting this error "Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\PHP\PHP_project\PHPforums\db_forum.php on line 24" Forum.php- contains a forum class. Below is the code for the Forum class:

<?php

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

}

?>
  • 写回答

1条回答 默认 最新

  • dosryjij88555 2014-06-17 18:22
    关注

    $stmt is not an object. This has happened because of an error before. Check if your statement has been created successfully. Perhaps you have an error in your query.

    Outputting the error will help you:

    echo $this->db_conn->error;
    

    See http://php.net/manual/de/mysqli.error.php

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数