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.


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.