2014-06-17 3 views
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; 
     } 
    } 


} 

객체 지향 PHP를 시도하고 있으며이 오류가 발생합니다. "치명적인 오류 : 비 멤버 객체에서 bind_param C : \ xampp \ htdocs \ PHP \ PHP_project \ PHPforums \ db_forum.php 24 행에있는 객체 " Forum.php- 포럼 클래스가 있습니다.치명적 오류 : 객체가 아닌 오류가 발생하면 bind_param() 멤버 함수를 호출하십시오.

<?php 

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

} 

?> 
+0

첫 번째 매개 변수는 인용되어야 참조하십시오. ''ss''에서와 마찬가지입니다. –

+0

Patrick은 "ss"를 의미합니다. PHP는 인용되지 않은 문자열을 상수로 평가합니다. 이 경우 그들은 정의되지 않을 것이다. –

+1

Sidenote :'execute()'를 두 번 포함하고 있습니다. 'if ($ stmt-> execute()) {' –

답변

2

$stmt 객체가 아닌 경우 : 아래는 포럼 클래스에 대한 코드입니다. 이것은 전에 오류로 인해 발생했습니다. 명령문이 성공적으로 작성되었는지 점검하십시오. 검색어에 오류가있는 것 같습니다.

오류를 출력하기 당신을 도울 것입니다 :

echo $this->db_conn->error; 

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

+0

감사합니다. 문제가 해결되었습니다. 나는 SQL 쿼리의 경우에는 소문자로 변경하고 잘 작동하는지 잘 모르겠습니다. – user3407447

관련 문제