Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Johnatan Guzman
Courses Plus Student 2,360 PointsIt doesnt show single shirts page anymore
I have this code in shirt.php
$id = $_GET["id"];
$product = get_product($id, $products);
if(!isset($product)) {
header("location: " . BASE_URL . "shirts/");
exit();
}
and this code in products.php
function get_product($shirt_id, $products){
if (isset($shirt_id)) {
$product_id = $shirt_id;
if(isset($products[$product_id])) {
return $product = $products[$product_id];
}
}
}
It worked before, but after including the database it always returns to the main shirts pages when clicking on a single shirt.
1 Answer

shezazr
8,275 Pointstry some basic debugging & var_dump info to confirm
- check id exists
- check products exist
- go through get_products and see what happens here?
btw:
""" function get_product($shirt_id, $products){ if (isset($shirt_id)) { $product_id = $shirt_id; if(isset($products[$product_id])) { return $product = $products[$product_id]; } } } """
You don't need: $product_id = $shirt_id; just use shirt_id in the next statement
and instead of: return $product = $products[$product_id];
just do
return $products[$product_id];
Johnatan Guzman
Courses Plus Student 2,360 PointsJohnatan Guzman
Courses Plus Student 2,360 PointsIt was fixed in the next video