我已经过了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);
答案 0 :(得分:4)
您从未检查$stmt
是否为对象。在这种情况下,它更有可能是FALSE
,这是PDO::prepare
在您的查询中出现错误时返回的内容。
您的查询中有错误,因为您没有在反引号中划分字段名称,timestamp
是关键字。
从第三方API 调用函数后检查错误,并修复您的查询。
答案 1 :(得分:1)
第一个;始终在localhost中运行您的查询,以查看您的查询是否正确执行。接下来,请务必确保您的字段和数据类型的名称与代码中的名称相对应