title: Notice: Undefined index on line 5
body: <p>I am getting the following error on a PHP &amp; MySQL application from <em>Murach's PHP and MySQL</em> book:    </p>
  
  <pre><code>Notice: Undefined index: category_id in C:\xampp\htdocs\book_apps\ch04_product_viewer\index.php on line 5
  </code></pre>
  
  <p>I didn't modified the code whatsoever (yet), so I assumed it should work out of the box. The application displays products from a database as it should, the only problem is I get this annoying error.</p>
  
  <p>Here is the PHP code of the index.php file:</p>
  
  <pre><code>&lt;?php
  require 'database.php';
  
  // Get category ID
  $category_id = $_GET['category_id'];
  if (!isset($category_id)) {
      $category_id = 1;
  }
  
  // Get name for current category
  $query = "SELECT * FROM categories
            WHERE categoryID = $category_id";
  $category = $db-&gt;query($query);
  $category = $category-&gt;fetch();
  $category_name = $category['categoryName'];
  
  // Get all categories
  $query = 'SELECT * FROM categories
            ORDER BY categoryID';
  $categories = $db-&gt;query($query);
  
  // Get products for selected category
  $query = "SELECT * FROM products
            WHERE categoryID = $category_id
            ORDER BY productID";
  $products = $db-&gt;query($query);
  ?&gt;
  </code></pre>