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!

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


Where does the product_id come from?

For this php code on the shirts.php page:

$product_id = $_GET["id"];
$product = $products[$product_id];

Are we getting the $product_id variable from the URL of the page? Since this page is directing us to "shirt.php?id=102" that means it's getting the id # 102 from the URL bar, not from products.php?

2 Answers

Kazimierz Matan
Kazimierz Matan
13,257 Points

$_GET is an array of values passed by URL (GET method of a form). We get a value of "id" (for instance "102") and then we retrieve from $products array a product with $product_id equal to 102.

Thanks Kazimierz! That helps a lot.