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

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

suyash patankar
suyash patankar
2,310 Points

Syntax error - books list not displayed

The code as shown in video

  <ul class="items">
        <?php  
foreach($catalog as $item){
      echo "<li><a href='#'><img src='"
        . $item["img"] . "' alt='"
        . item["title"] . "'  />"
        . "<p>View details</p>" 
        . "</a></li>";
    }
        ?>
      </ul>

is giving a syntax error Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/treehouse/workspace/catalog.php on line 40

line 40 is . item["title"] . "' />"

suyash patankar
suyash patankar
2,310 Points

code is not displayed properly here, but please help with foreach loop part

edited for syntax highlighting. :)

4 Answers

Sadly no -- my first (uninformed) thought is that you're missing the '$' on the second item['title'], but I really don't know enough PHP to have anything constructive to say. :)

suyash patankar
suyash patankar
2,310 Points

Thank you @Cena Mayo

any solution for error removal?

suyash patankar
suyash patankar
2,310 Points

yes, I think that is the issue, thank you so much, I am also new to php

suyash patankar
suyash patankar
2,310 Points

It worked, you can close this discussion, thank you very much for your help @Cena Mayo