gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:03 24 4
gpt4 key购买 nike

我已经检查了这个脚本 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 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);

最佳答案

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

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

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

关于PHP fatal error : Call to a member function bind_param(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6970806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com