PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying All Items

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 86,642 Points

Help! Where are the images?

They're not picking up from the data file, which is successfully linked.

This is my code.

A portion of my data,php file.


$catalog[101] = [
    "title" => "A Design Patterns: Elements of Reusable Object-Oriented Software",
    "img" => 'img/media/design_patterns.jpg',
    "genre" => "Tech",
    "format" => "Paperback",
    "year" => 1994,
    "category" => "Books",
    "authors" => [
        "Erich Gamma",
        "Richard Helm",
        "Ralph Johnson",
        "John Vlissides"
    "publisher" => "Prentice Hall",
    "isbn" => '978-0201633610'
                <ul class = "items">
                        foreach($catalog as $item) {
                        echo "<li><a href='#'><img src'" 
                        . $item["img"] . "' alt='"
                        . $item["title"] . "' />"
                        . "<p>View Details</p>"
                        . "</a></li>";                


The files are in the right place... the includes link correctly, I've tried tinkering with the file extension... they're just not showing up on localhost.

it is working on workspace? then if the image is not showing properly usually it's about the permission or owner group try to check permission on your image folder and image itself

1 Answer

Can you inspect the element and paste in the image source?

It looks like your html is invalid - you need an '=' after src:

<img src="/some-source">

Right now you're printing

<img src"/some-source">

Also, why use single quotes in your html? I would flip the php string to use single quotes and html to use double quotes :-)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 86,642 Points

The quote stuff is just something I tried to get the images to appear. But the dodgy source attribute is something I simply didn't see. That's bound to be it, thanks :)