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 Enhancing a Simple PHP Application Adding Search: Controller & View Accounting for Empty Results

Benjamin Payne
Benjamin Payne
7,167 Points

Can't figure out what's wrong with my code in this challenge

The Preview button doesn't work, and I have come back to this challenge a few different times. I feel like my code is right - cannot figure out what is wrong.

index.php
<?php

    $recommendations = array();

?><html>
<body>

    <h1>Flavor Recommendations</h1>

  <?php if (!empty($recommendations) {
        echo "<ul>";
          foreach($recommendations as $flavor) {
            echo "<li>" . $flavor . "</li>";
          }
        echo "</ul>";
        } ?>
</body>
</html>

5 Answers

Hi Benjamin Payne,

it seems like you forgot to close the if statement properly because it is missing the closing parenthese. It is in the line which checks if $recommendations is empty.

Got it?

Benjamin Payne you have:

<?php

<?php if (!empty($recommendations) {

and you need

<?php if (!empty($recommendations)) {

look closely at the two closing parenthese. You need one to close the if condition and another to close the empty function.

Benjamin Payne
Benjamin Payne
7,167 Points

I put it down before the </body> tag so that it encloses the whole thing. Is that wrong?

Benjamin Payne
Benjamin Payne
7,167 Points

Good grief. Thank you. I always try to check that stuff first, but I still missed it.

I know that feeling when you think you have made everything correct and the mistake shouldn't be on part of your side and you struggle and in the end it is just such a small typing error :-)

You wont believe the number of times this particular syntax error got me when I started out - and still now!!