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 Integrating PHP with Databases Using Relational Tables Adding a Secondary Query

Why do we need to return $item when we have that in the details.php as a redirect?

Why do we need to do a return on the $item for empty values? We already have this in the details.php as a redirect:

if(empty($item)){
    header("location:catalog.php");
    exit;
}

What are the scenarios that will trigger this line of code?

1 Answer

Niki Molnar
Niki Molnar
25,698 Points

Hi Dennis

I'm presuming that you mean that functions.php -> function single_item_array($id) is run before checking whether the result is empty?

I think you're right - I would personally have coded it as:

$id = filter_input(INPUT_GET,"id",FILTER_SANITIZE_NUMBER_INT);
if ($id) {
   $item = single_item_array($id);
} else {
   header("location:catalog.php");
   exit;
}

or

if (filter_input(INPUT_GET,"id",FILTER_SANITIZE_NUMBER_INT) > 0) {
...
}

It would be interesting to hear the thoughts of others.

Niki