【发布时间】:2015-10-01 01:27:07
【问题描述】:
我正在从表单发送一组值。我想循环查找这些 ID 的数据库表。当我收到这条消息时,我明白出了点问题......
致命错误:在第 56 行的 /home/d15155/tool/pdf.php 中的非对象上调用成员函数 bind_param()
if (count($_POST['q']) == 0){
}
else {
foreach($_POST['q'] as $quality){
# Prepare statement
$stmt = $mysqli->prepare("SELECT the_question, the_sub_questions, the_quality, the_time FROM my_questions WHERE the_category='2' AND the_headline='5' AND quality_id = ? ORDER BY the_sort_order ASC");
$stmt->bind_param('i', $quality);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($the_question, $the_sub_questions, $the_quality, $the_time);
$stmt->fetch();
$konkretaexempel .= utf8_encode($the_question) . " <br />";
}
}
我想将结果添加到一个长字符串中(然后在 PDF 中使用)。
编辑
删除了 foreach 和数组,但仍然收到相同的错误消息。我检查了,数据库连接正常。
if (count($_POST['q']) == 0){
}
else {
$stmt = $mysqli->prepare("SELECT the_question, the_sub_questions, the_quality, the_time FROM my_questions WHERE the_category='2' AND the_headline='5' AND quality_id = ? ORDER BY the_sort_order ASC");
$stmt->bind_param('i', '27');
$stmt->execute();
$stmt->bind_result($the_question, $the_sub_questions, $the_quality, $the_time);
$stmt->fetch();
$konkretaexempel .= utf8_encode($the_question) . " <br />";
}
【问题讨论】:
-
您似乎截断了错误消息;您可能需要编辑您的问题以包含完整的消息。
-
这意味着
prepare不起作用。尝试在语句中添加 ` 周围的列名 -
旁注:
->prepare()的目的是让您无需在每次循环迭代时调用它。通过将其放在您的foreach()中,您正在浪费它的最佳功能/特性之一。