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

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