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

Brian O'Connor
Brian O'Connor
13,226 Points

Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file in /home/treehouse/workspace/details.php on

Hi, I'm getting the following error message when I try to display any of the items in the catalogue,

my code looks like this

  <?php 
if (strtolower($item["category"]) == "books"); { ?>
      <tr>
        <th>Authors</th>
        <td><?php echo implode(", ",$item["authors"]); ?></td>
        </tr>
        <tr>
        <th>Publisher</th>
        <td><?php echo $item["publisher"]; ?></td>
        </tr>
        <tr>
        <th>ISBN</th>
        <td><?php echo $item["isbn"]; ?></td>
        </tr>


        <?php } else if (strtolower($item["category"]) == "movies") { ?>
        <tr>
        <th>Director</th>
        <td><?php echo ,$item["director"]; ?></td>
        </tr>
        <tr>
        <th>Writers</th>
        <td><?php echo implode(", ",$item["writers"]); ?></td>
        </tr>
        <tr>
        <th>Stars</th>
        <td><?php echo implode(", ",$item["stars"]); ?></td>
        </tr>

         <?php } else if (strtolower($item["category"]) == "music") { ?>
        <tr>
        <th>Artist</th>
        <td><?php echo ,$item["artist"]; ?></td>
        </tr>
        <?php }?>

I am not seeing the error in the else if statement - my code should the same as the code used in the video - what am I missing ?

many thanks Brian

2 Answers

You've got a semi colon in front of your first if argument. Also, get rid of those commas that come after your echo statements. Do that and everything should work perfectly B)

Brian O'Connor
Brian O'Connor
13,226 Points

Thank you very much for that, the semi colon was the biggest culprit. I'm finding the most common mistake in my code so far on this learning journey is usually always a spelling or a single misplacement of a comma, colon, semi colon etc.

thank you again B