While working through the Product Manager application in Murach’s Chapter 4, I was getting errors on the following statement:
1: if(!isset($category_id)) { 2: $category_id = $_GET['category_id']; 3: if (!isset($category_id)) { 4: $category_id = 1; 5: } 6: }
The error was an invalid index for the expression on line 2.
Notice: Undefined index: category_id in C:\xampp\htdocs\ cs601\week4\HW\index.php on line [2]
I had originally rewritten the code, but also tried with a direct copy and paste. I fixed the error using the isempty function:
1: if (!isset($category_id)) { 2: if (!empty($_GET)) { 3: $category_id = $_GET['category_id']; 4: } else { 5: $category_id = 1; 6: }
(Note, I’m running in PHP 5.3.5, the book requires 5.3.)
Hi, Paul. I also had the same error while testing “Product Manager” application.
I think that it’s an obvious error which the authors of the book haven’t noticed.
I used this code to fix it:
if (!isset($_GET[‘category_id’]))
$category_id = 1;
else
$category_id = $_GET[‘category_id’];