PHP致命错误:调用成员函数bind_param()

PHP致命错误:调用成员函数bind_param(),php,mysql,Php,Mysql,我已经把这个剧本看了30遍了,我一辈子都找不到我的问题。代码如下: function redeem() { $case = $_POST["case"]; $name = $_POST["name"]; $profession = $_POST["profession"]; $city = $_POST["city"]; $country = $_POST["country"]; $totalp

我已经把这个剧本看了30遍了,我一辈子都找不到我的问题。代码如下:

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致命错误:在第105行的非对象上调用成员函数bind_param()

代码:

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

您从未检查过
$stmt
是否为对象。在这种情况下,它更可能是
FALSE
,这是当查询中有错误时
PDO::prepare
返回的结果

您的查询中有一个错误,因为您没有在backticks中分隔字段名,
timestamp
是一个关键字


从第三方API调用函数后检查错误,并修复您的查询。

您从未检查过
$stmt
是否为对象。在这种情况下,它更可能是
FALSE
,这是当查询中有错误时
PDO::prepare
返回的结果

您的查询中有一个错误,因为您没有在backticks中分隔字段名,
timestamp
是一个关键字


从第三方API调用函数后检查错误,并修复您的查询。

首先;始终在localhost中运行查询,以查看查询执行时是否没有错误。接下来,始终确保字段和数据类型的名称与代码中的名称一致;始终在localhost中运行查询,以查看查询执行时是否没有错误。接下来,始终确保字段和数据类型的名称与代码中的名称一致

也许我对PHP太生疏了,但我认为我们需要看看$this->db是如何声明的。听起来$this->db->prepare实际上并没有返回一个对象。可能的重复可能是我对PHP太生疏了,但我想我们需要看看$this->db是如何声明的。听起来$this->db->prepare实际上并没有返回对象。可能与+1重复,请注意,“case”也是一个,因此也需要转义。它是字段列表
中的第一个字段。。。learnent_cases_排行榜(case,
当然…愚蠢的错误。感谢各位!现在我将“case”和“timestamp”更改为不同的名称,不会发生冲突,脚本运行得很好!+1,请注意,“case”也是一个,因此也需要转义。它是字段列表中的第一个字段
…learnent_cases_排行榜(case,…
当然……愚蠢的错误。谢谢大家!现在我将“case”和“timestamp”改成了不同的名称,不会发生冲突,脚本运行得很好!