这是我的php网站上的代码,此页面显示为空白,但显示登录用户的标题菜单除外。我只是找不到错误。 由于favitems表为空,因此应显示您没有任何产品消息。
<?php
include("includes/config.php");
include 'includes/header.php';
if(!isset($_SESSION['username'])){
header("Location:login.php");
}else{
$test = mysql_query("SELECT * FROM favitems
WHERE id = '".$_SESSION['username']."'")
or die("ERROR :<hr>".mysql_error());
if($test == NULL){
echo "<div class=products>";
echo "<br>You have no products to show!";
echo "</div>";
} else {
While ($row = mysql_fetch_array($test)){
echo "<div class='products'>";
$id = $row['itemid'];
$query = mysql_query("SELECT * FROM products
WHERE id =".$id);
$q = mysql_fetch_array($query);
echo $q['item_name']." "; echo $q['brand_name']."<br>";
echo $q['qty']."<br>";
echo $q['category']."<br>";
echo $q['state']."<br>";
echo "<br><a href=view.php?id=".$q['item_id'].">
View item</a>";
}
echo "</div>";
}
}
include("includes/footer.php");
?>
答案 0 :(得分:1)
if(!isset($_SESSION['username'])){
header("Location:login.php");
exit;
}
1. Execute your query here
2. If error found throw Error message
3. If successful execution, Check no of rows fetched
if(row_fetched > 0 ) {
// print table
} else {
// print no recors found
}
include("includes/footer.php");
同时检查您在此处使用的所有内置函数的变量范围和返回值。