我从窗体发送一个值的数组。我想遍历数据库表寻找这些ID。当我得到这个消息我明白了什么是错的...MySQLi foreach bind_param()
致命错误:调用一个成员函数bind_param()一个非对象在/home/d15155/tool/pdf.php在线56
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中使用)。
EDIT
删除了的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 />";
}
它看起来像你截断了错误信息;您可能需要编辑您的问题以包含完整的讯息。 –
这意味着'准备'不起作用。尝试在你的语句中添加\'aroung列名 – Random
注意:' - > prepare()'的目的是让你不必在每次循环迭代时调用它。通过将它放入你的'foreach()'中,你正在浪费其最好的功能/特性之一。 – Sean