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

}

?>
fortune
  • 3,361
  • 1
  • 20
  • 30

1 Answers1

2

$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

theHacker
  • 3,984
  • 1
  • 19
  • 34
  • Thanks all, I have fixed the issue. I am not very sure with the case of SQL query, changed it to lower case and it worked. – user3407447 Jun 17 '14 at 18:54