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 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!!