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 trialDaniel Luke
Courses Plus Student 7,151 PointsWhy is this throwing an error???
The code below throws an error for some reason. I've gone over it again and again, I have no idea what's wrong except that it's something on line 59: echo '<img src="' . $product["img"] . '" alt="' . $prodcut["name"] . '">';
The error message reads as follows: notice: undefined variable: prodcut in c:\xampp\htdocs\shirts.php on line 59
Please advise!
<?php
$products[101] = array(
"name" => "Logo Shirt, Red",
"img" => "img/shirts/shirt-101.jpg",
"price" => 18
);
$products[102] = array(
"name" => "Mike the Frog Shirt, Black",
"img" => "img/shirts/shirt-102.jpg",
"price" => 20
);
$products[103] = array(
"name" => "Mike the Frog Shirt, Blue",
"img" => "img/shirts/shirt-103.jpg",
"price" => 20
);
$products[104] = array(
"name" => "Logo Shirt, Green",
"img" => "img/shirts/shirt-104.jpg",
"price" => 18
);
$products[105] = array(
"name" => "Mike the Frog Shirt, Yellow",
"img" => "img/shirts/shirt-105.jpg",
"price" => 25
);
$products[106] = array(
"name" => "Logo Shirt, Gray",
"img" => "img/shirts/shirt-106.jpg",
"price" => 20
);
$products[107] = array(
"name" => "Logo Shirt, Turquoise",
"img" => "img/shirts/shirt-107.jpg",
"price" => 20
);
$products[108] = array(
"name" => "Logo Shirt, Orange",
"img" => "img/shirts/shirt-108.jpg",
"price" => 25,
);
?><?php $pageTitle = "Mike's Full Catalog of Shirts"; $section = "shirts"; include ('inc/header.php') ?>
<div class="section shirts page">
<div class="wrapper">
<h1>Mike’s Full Catalog of Shirts</h1>
<ul class="products">
<?php foreach($products as $product) {
echo "<li>";
echo '<a href="#">';
echo '<img src="' . $product["img"] . '" alt="' . $prodcut["name"] . '">';
echo "<p>View Details</p>";
echo "</a>";
echo "</li>";
}
?>
</ul>
</div>
</div>
<?php include ('inc/footer.php') ?>
2 Answers
Leonardo Hernandez
13,798 PointsHi Daniel,
Misspelling a $product variable from what I can see. Don't know if it is line 59 or not..
Check your variables for spelling
You are not alone!
Daniel Luke
Courses Plus Student 7,151 PointsThanks, finally see it!
Leonardo Hernandez
13,798 PointsLeonardo Hernandez
13,798 PointsActually, it says right there in the error what variable it is.