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 trialHanah Yendler
3,625 PointsThe way PHP works/product displays
I have a question as to why (and I think this has to do more with how PHP works than maybe my code, unless there is something wrong with it that I don't see - if I leave the original only 4 shirts, and not copy the code of all 8 shirts arrays from the the text file, the code doesn't run and all I get is a blank page.
So when I just leave my code like this at the top:
<?php
$products = array();
$products[101] = array(
"name" => "Logo Shirt, Red",
"price" => 18
"img" => "img/shirts/shirt-101.jpg"
);
$products[102] = array(
"name" => "Mike the Frog Shirt, Black",
"price" => 20,
"img" => "img/shirts/shirt-102.jpg"
);
$products[103] = array(
"name" => "Mike the Frog Shirt, Blue",
"price" => 20,
"img" => "img/shirts/shirt-103.jpg"
);
$products[104] = array(
"name" => "Logo Shirt, Gray",
"price" => 18,
"img" => "img/shirts/shirt-104.jpg"
);
?><?php
The page won't display, as opposed to when I copy and paste the rest of the products. Can someone explain to me why this is? Is there somewhere in the CSS/PHP an expectation that there has to be that exact number of shirts from the text file? I'm just mulling this over.
1 Answer
Aaron Frey
6,672 PointsIt looks like you are missing a coma in this code block after the price
$products[101] = array(
"name" => "Logo Shirt, Red",
"price" => 18
"img" => "img/shirts/shirt-101.jpg"
);
Also, there is an extra <?php tag at the end of the code. Remove that.
Fix those two things and see if the code runs properly.
Hanah Yendler
3,625 PointsAh, so it was a coding error on my part (code can be so unforgiving sometimes). Thank you! (The extra php was just for the code after).
Aaron Frey
6,672 PointsAaron Frey
6,672 PointsYou're welcome. Commas can drive a person crazy.