too long

This is a code on my php website where this page comes out blank except header menu which shows logged in user. I just can't find the error. Since favitems table is empty, it should display you do not have any product message.

<?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");
?>
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");

Also Check you variable scope and return values of all inbuilt function you are using here.