我完全感到困惑。我的整个页面代码如下。
最初,我在页面顶部包含 header.php、sidebar、topMenuBar 和 mainContentShell,在它之后运行第一个查询,然后是第二个查询,等等页面的其余部分。一切正常。不过,我的第一个查询有所不同...我检查了 $_GET['stone'] 数字是否大于零且小于 select max(StoneID),但如果有人手动输入 StoneID,我仍然会出错从库存中删除的石头。我修改了我的 $_GET 验证计划,并将其移到包含的文件上方,以便 header() 重定向可以正常工作。现在,我的第二个查询不起作用,即使它完全没有改变。
Var_dump($querySN)产生string(53) "select StoneName from stonetypes where StoneID = '1'"和var_dump($resultSN)产生NULL。它指出:第 35 行发生错误 --- $resultSN = $db->query($querySN); 状态数次:无法获取 mysqli 状态数次:尚不允许属性访问 结论是:在第 36 行对非对象调用成员函数 fetch_assoc() ---$rowSN = $resultSN ->fetch_assoc();
有谁知道这里发生了什么以及我该如何解决?页面代码如下。谢谢!!!
<?php
require('./inc/config.inc.php');
$stone = (INT)$_GET['stone'];
require(MYSQL1);
$queryCk = "select StoneID from stonetypes";
$resultCk = $db->query($queryCk);
$var = array();
while ($rowCk = $resultCk->fetch_assoc()){
$var[] = $rowCk['StoneID'];
}
if(!in_array($stone, $var)) {
header('Location: beadgallery.php?type=stones');
exit;
} else {
include('inc/header.inc.php');
include('inc/sidebar.inc.php');
include('inc/topMenuBar.inc.php');
include('inc/mainContentShell.inc.php');
?>
<div id="mainContent">
<div class="center">
<?php
$querySN = "select StoneName from stonetypes where StoneID = '$stone' ";
$resultSN = $db->query($querySN);
$rowSN = $resultSN->fetch_assoc();
echo '<table id="cartDisplayTable">';
echo '<tr>';
echo '<td colspan="2">';
echo '<table id="titleTable">';
echo '<tr>';
echo '<td id="stoneTitle">';
if (isset($rowSN['StoneName'])){
echo '<h2>'.ucwords($rowSN['StoneName']).'</h2>';}
echo '</td>';
echo '</tr>';
$query = "select * from organized_inventory2 where StoneID = '$stone' ";
$result = $db->query($query);
$num_beadItems = $result->num_rows;
$justused='abc';
for ($i=0; $i < $num_beadItems; $i++) {
$row = $result->fetch_assoc();
if (!isset($row['itmphoto'])) {
echo '</table>';
echo '</td>';
echo '</tr>';
echo '<tr><td colspan="2"><hr id="cartDivider"></td></tr>';
echo '<tr>';
echo '<td id="cartImgCell">';
echo '<img src="img/nophoto.gif">';
echo '</td>';
echo '<td id="cartInfoCell">';
echo '<table id="innerTable">';
include ('inc/stoneCartInfo.inc.php');
} elseif ($row['itmphoto'] == $justused) {
echo '<tr><td colspan="2"><hr id="itemDivider"></td></tr>';
include ('inc/stoneCartInfo.inc.php');
} else {
echo '</table>';
echo '</td>';
echo '</tr>'
;
echo '<tr><td colspan="2"><hr id="cartDivider"></td></tr>'
;
echo '<tr>';
echo '<td id="cartImgCell">';
echo '<img src="img/invent/'.$row['itmphoto'].'">';
$justused = $row['itmphoto'];
echo '</td>';
echo '<td id="cartInfoCell">';
echo '<table id="innerTable">';
include ('inc/stoneCartInfo.inc.php'); }
}
echo '</table>'
;
echo '</td>';
echo '</tr>'
;
echo '</table>'
;
}
$result->free();
unset($result);
$db->close();
?>
</div> <!-- div class="center" -->
</div> <!-- div id="mainContent" -->