Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:36:20+00:00 2026-05-28T17:36:20+00:00

I am getting the following error on a PHP & MySQL application from Murach’s

  • 0

I am getting the following error on a PHP & MySQL application from Murach’s PHP and MySQL book:

Notice: Undefined index: category_id in C:\xampp\htdocs\book_apps\ch04_product_viewer\index.php on line 5

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.

Here is the PHP code of the index.php file:

<?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->query($query);
$category = $category->fetch();
$category_name = $category['categoryName'];

// Get all categories
$query = 'SELECT * FROM categories
          ORDER BY categoryID';
$categories = $db->query($query);

// Get products for selected category
$query = "SELECT * FROM products
          WHERE categoryID = $category_id
          ORDER BY productID";
$products = $db->query($query);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:36:21+00:00Added an answer on May 28, 2026 at 5:36 pm

    It’s a notice rather than an error, meaning PHP tells you something it thinks is wrong, but the code is executed unhindered. The reason is that if you don’t pass category_id in the query string, the corresponding element in the GET array does not exist.

    There is a lot of legacy PHP code that doesn’t check for the existence of array elements – in those cases, it’s often unavoidable to change the error reporting level to simply mute the notices. It can also be argued that accessing a GET parameter shouldn’t trigger this kind of notice at all.

    However, adjusting the error reporting level is regarded bad practice, as notices can often be very useful. So when writing new code, add the necessary checks so this doesn’t happen.

    The proper way to do this without getting a notice would be

    if (isset($_GET['category_id']))
     $category_id = $_GET['category_id'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm getting the following error Notice: Undefined offset: 1 in file.php on line
I'm having a little issue with Doctrine. Im getting the following error: PHP Fatal
I'm supposed to be getting XML output from the following php file that is
I keep getting the following error in my log PHP Parse error: syntax error,
Using the Facebook PHP SDK, I'm getting the following error when I try to
I am getting the following errors: PHP Warning: Module 'ldap' already loaded in Unknown
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting following error when I am trying to get WebResponse using WebResponse
I am getting following error message when using Doctrine ORM in Codeigniter. ( !
SOLVED in the last answer im getting following error, dunno where and why? cause

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.