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 trialJohnatan 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