本文介绍了PHP致命错误:调用成员函数bind_param()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遍历了30多次此脚本,但我一生都找不到我的问题.这是代码:

I've gone over this script like 30 times, and I can't for the 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:

第105行是此行:

代码:

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

推荐答案

您从未检查$stmt是对象.在这种情况下,它更有可能是FALSE,这是当您的查询中有错误时PDO::prepare返回的内容.

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.

您的查询中有一个错误,因为您没有在反引号中分隔字段名称,并且timestamp是关键字.

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

从第三方API调用功能后检查错误,并修复查询.

这篇关于PHP致命错误:调用成员函数bind_param()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:59