Hey guys
I am getting this error Notice: Undefined index: catid in C:\wamp\www\chapter25\index.php on line 24
Here is the code from the index.php
<?php
//connect to database
$conn = mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("book_sc",$conn) or die(mysql_error());
$display_block = "<h1>My Categories</h1>
<P>Select a category to see its items.</p>";
//show categories first
$get_cats = "select catid, catname from categories order by catname";
$get_cats_res = mysql_query($get_cats) or die(mysql_error());
if (mysql_num_rows($get_cats_res) < 1) {
$display_block = "<P><em>Sorry, no categories to browse.</em></p>";
} else {
while ($cats = mysql_fetch_array($get_cats_res)) {
$cat_id = $cats['catid'];
$cat_title = strtoupper(stripslashes($cats['catname']));
$display_block .= "<p><strong><a href=\"$_SERVER[PHP_SELF]?catid=$cat_id\">$cat_title</a></strong><br></p>";
if ($_GET['catid'] == $cat_id) {
//get items
$get_items = "select catid, title, price from books where cat_id = $cat_id order by title";
$get_items_res = mysql_query($get_items) or die(mysql_error());
if (mysql_num_rows($get_items_res) < 1) {
$display_block = "<P><em>Sorry, no items in this category.</em></p>";
} else {
$display_block .= "<ul>";
while ($items = mysql_fetch_array($get_items_res)) {
$item_id = $items[catid];
$item_title = stripslashes($items[title]);
$item_price = $items[price];
$display_block .= "<li><a href=\"showitem.php?item_id=$item_id\">$item_title</a></strong> (\$$item_price)";
}
$display_block .= "</ul>";
}
}
}
}
?>
<html>
<head>
</head>
<body>
<? print $display_block; ?>
</body>
</html>