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
Adam Zuckerberg
22,248 PointsBuild a Simple (NOT!) PHP Application - $GET
I keep getting this error on the localhost website:Notice: Undefined index: id in C:\xampp\htdocs\shirt.php on line 3 array(4) { ["name"]=> string(15) "Logo Shirt, Red" ["img"]=> string(24) "img/shirts/shirt-101.jpg" ["price"]=> int(18) ["paypal"]=> string(13) "H7DSWSKWHNARY" } (I get that error when I replace line 4 with "101" instead of the $product_id variable, and if I leave it as is. I get this: Notice: Undefined index: id in C:\xampp\htdocs\shirt.php on line 3
Notice: Undefined index: in C:\xampp\htdocs\shirt.php on line 4 NULL I pasted in the project files "shirt.php" just to make sure it was accurate, but I am still getting these errors. My code looks like this: <?php include("inc/products.php");
$product_id = $_GET["id"]; $product = $products[$product_id];
?><pre><?php
echo $product_id . "\n"; var_dump($product);
?></pre>
3 Answers
Fraser Boag
6,381 PointsNot sure of your level with PHP, so apologies if this is insultingly obvious, but are you definitely setting the "id" superglobal in the URL? i.e. are you navigating to shirt.php?id=1 (or whatever), as I imagine that this error could appear were you simply to navigate to shirt.php.
Véronique Bellamy
20,810 PointsYou might want to consider an isset loop. Like this:
<?php
if (isset($_GET['id'])) {
$product_id = $_GET["id"]; $product = $products[$product_id];
echo "<pre>" . $product_id . "\n";
echo var_dump($product);
echo "</pre>";
exit();
}
?>
Adam Zuckerberg
22,248 Points$Level_of_frustration_with_this_course_on_a_scale_of_1_to_10 = 10