2011-08-07 4 views
0

나는이 스크립트를 30 번 이상 사용 했으므로 저의 인생에서 내 문제를 찾을 수 없습니다.PHP 치명적인 오류 : member 함수 bind_param()을 호출하십시오.

function redeem() { 

     $case = $_POST["case"]; 
     $name = $_POST["name"]; 
     $profession = $_POST["profession"]; 
     $city = $_POST["city"]; 
     $country = $_POST["country"]; 
     $totalpercent = $_POST["totalpercent"]; 
     $pretest = $_POST["pretest"]; 
     $posttest = $_POST["posttest"]; 
     $investigationspercent = $_POST["investigationspercent"]; 
     $timesreset = $_POST["timesreset"]; 
     $creditsspent = $_POST["creditsspent"]; 
     $timescompleted = $_POST["timescompleted"]; 

     //Add the information to the learnent_cases_leaderboard table 
     $stmt = $this->db->prepare("INSERT INTO learnent_cases_leaderboard (case, name, profession, city, country, totalpercent, pretest, posttest, investigationspercent, creditsspent, timescompleted, timesreset, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)"); 

     $stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset); //the quotations specify the type of variable; 
     //See http://php.net/manual/en/mysqli-stmt.bind-param.php for more information on bind_param 
     $stmt->execute(); 
     $stmt->close(); 

I 오류 로그를 확인, 그것은 나에게이 오류 메시지가 있습니다 :

라인 (105)이 라인 :

PHP Fatal error: Call to a member function bind_param() on a non-object on line 105

코드 :

$stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset); 
여기에 코드입니다
+0

어쩌면 저는 제 PHP로 녹슬지는 모르지만 $ this-> db가 선언 된 방법을 알아야 할 필요가 있다고 생각합니다. $ this-> db-> prepare는 실제로 객체를 반환하지 않는 것처럼 들립니다. – Kris

+0

[참고 - PHP에서이 오류는 무엇을 의미합니까?] (http://stackoverflow.com/questions/12769982/reference-what-this-error-mean-in-php) –

답변

4

$stmt은 (는) 개체가 아닙니다. 이 경우 FALSE 일 가능성이 높으며 쿼리에 오류가있는 경우 PDO::prepare이 반환합니다.

backticks에서 필드 이름을 한정하지 않았고 timestamp이 키워드이기 때문에 쿼리에 오류가 있습니다.

제 3 자 API에서 함수를 호출 한 후 오류를 확인하고 쿼리를 수정하십시오.

+2

+1, 참고 "case"는 [mysql의 키워드] (http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html)이기 때문에 이스케이프해야합니다. – vstm

+0

필드 목록의 첫 번째 필드 '... learnent_cases_leaderboard (case, ...' – vstm

+0

물론 ... 어리석은 실수. 감사합니다! 이제 "케이스"와 "타임 스탬프"를 다른 이름으로 변경했습니다. 스크립트가 완벽하게 실행됩니다. –

1

우선; 쿼리가 오류없이 실행되는지 확인하려면 항상 로컬 호스트에서 쿼리를 실행하십시오. 다음 필드와 데이터 유형의 이름이 코드에있는 것과 일치하는지 항상 확인하십시오

관련 문제