what is the problem with this code?

<body bgcolor="#FFFF00">
<div align="center">
  <table width="284" border="4" cellspacing="2" cellpadding="2">
    <tr>
      <td width="92">cat_id</td>
      <td width="79">cat_name</td>
      <td width="79">choose product </td>
    </tr>
    <?php
$id=$_GET['id'];
$con=mysql_connect("localhost","root","");
mysql_select_db("niladri",$con);
$sql="SELECT * FROM `subcategory`whare `cat_id`=`$id`";
$res=mysql_query("$sql",$con);
while($row=mysql_fetch_array($res))
{
?>
    <tr>
      <td><?php echo $row[subcat_id];?></td>
      <td><?php echo $row[subcat_name];?></td>
      <td><a href="fetch3.php"?id=<?php echo $row[subcat_id]?>>click</a></td>
    </tr>
    <?php
    }
    ?>
  </table>
</div>
</body>

it is showing an warning--->

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\htdocs\Niladri's PHP Programs\PROJECT\fetch2.php on line 16

the previous page fetch1.php code is.....

<?php
ob_start();
session_start();
$sidf=session_id();
session_register('sidf');
?>
<body bgcolor="#FFFF00">
<div align="center">
  <table width="284" border="4" cellspacing="2" cellpadding="2">
    <tr>
      <td width="92">cat_id</td>
      <td width="79">cat_name</td>
      <td width="79">choose subcategory </td>
    </tr>
    <?php

$con=mysql_connect("localhost","root","");
mysql_select_db("niladri",$con);
$sql="SELECT * FROM `category`";
$res=mysql_query("$sql",$con);
while($row=mysql_fetch_array($res))
{
?>
    <tr>
      <td><?php echo $row['cat_id'];?></td>
      <td><?php echo $row['cat_name'];?></td>
      <td><a href="fetch2.php"?id=<?php print $row['cat_id'];?>">click</a></td>
    </tr>
    <?php
    }
    ?>
  </table>
</div>
</body>

please send me a quick reply:(

Edited 3 Years Ago by Reverend Jim: Fixed formatting

mysql_select_db($dbid) or die("unable to connect");
$sql="SELECT * FROM subcategory where cat_id='$id'";
$res=mysql_query($sql);
This article has been dead for over six months. Start a new discussion instead.