Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Categories

Notice: Undefined index: catagory in /home/treehouse/workspace/inc/functions.php on line 17

here is my code from the page the error referenced

<?php
function get_item_html($id, $item){
  $output = "<li><a href='#'><img src='"
            .$item["img"]
            ."' alt='"
            .$item["title"]."'> 
            <p>view details</p> 
            </a></li>";
  return $output;
}
//catagory is in data.php as a $catalog array key
function array_catagory($catalog, $catagory){
  $output = array();

  foreach ($catalog as $id => $item){
//    catagory passed compared to catagory looped through
    if(strtolower($catagory) == strtolower($item["catagory"])){
//      if true add the id to $output array
      $output[] = $id;

     } /*if*/
   } /*foreach*/
  return $output;
} /*call fn from catalog page*/
//go to index.php, copy call to fn array_rand AND foreach loop

insight is appreciated

this is line 17 that is referenced as having the error

if(strtolower($catagory) == strtolower($item["catagory"])){

2 Answers

Simon Coates
Simon Coates
28,694 Points

could be a spelling mistake, if you're getting a value from the database. 'category'. This glitch usually means there's a discrepancy between what is in a value and what you think is in it. you can use var_dump to see what is in $item. something like:

var_dump($item);
exit;

I'll try that

yes, it was a spelling error. Mom was right...I should have paid attention in grammar school 0.o).