开发者

PHP Fatal error: Call to a member function bind_param()

开发者 https://www.devze.com 2023-03-26 05:09 出处:网络
I\'ve gone over this script like 30 times, and I can\'t for th开发者_开发知识库e life of me find my problem. Here is the code:

I've gone over this script like 30 times, and I can't for th开发者_开发知识库e life of me find my problem. Here is the code:

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();

When I look at the error log, it gives me this error message:

Line 105 is this line:

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

Code:

$stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset);


You never checked that $stmt is an object. In this case, it's more likely to be FALSE, which is what PDO::prepare returns when your query has an error in it.

And your query has an error in it, because you did not delimit your field names in backticks and timestamp is a keyword.

Check for errors after invoking functions from 3rd party APIs, and fix your query.


First of; always run your queries in the localhost to see if your query executes without error. Next always make sure your the names of the fields and data types corresponds with what you have in your code

0

精彩评论

暂无评论...
验证码 换一张
取 消