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.

PHP Build a Simple PHP Application Listing Inventory Items Displaying All Products

Hanah Yendler
Hanah Yendler
3,625 Points

The 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.

Aaron Frey
Aaron Frey
6,672 Points

You're welcome. Commas can drive a person crazy.

1 Answer

Aaron Frey
Aaron Frey
6,672 Points

It 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
Hanah Yendler
3,625 Points

Ah, 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).