2011-08-07 38 views
0

私はこのスクリプトを30回も実行しましたが、私の人生では問題が見つかりません。ここでは、コードは次のとおりです。PHP致命的なエラー:メンバー関数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(); 

私はエラーログを見ると、それは私にこのエラーメッセージを表示します。

ライン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が返されます。

バックテックでフィールド名を区切っていないためクエリにエラーがあり、timestampがキーワードです。

サードパーティの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

常にローカルホストでクエリを実行して、クエリがエラーなしで実行されるかどうかを確認します。次に、フィールドとデータ型の名前がコード内のものと一致することを確認してください。

関連する問題