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 Escaping Output Review

Gabi Udrescu
Gabi Udrescu
11,539 Points

Cannot pass a simple code challenge


For a very simple task I cannot manage to go forward, although I can validate the output in a PHP file on my local server.

The code is below:



$search_term = "";
if (isset($_GET["s"])) {
    $search_term = trim($_GET["s"]);
    if ($search_term != "") {
        require_once(ROOT_PATH . "inc/products.php");
        $products = get_products_search($search_term);

$pageTitle = "Search";
$section = "search";
include(ROOT_PATH . "inc/header.php"); ?>

    <div class="section shirts search page">

        <div class="wrapper">


            <form method="get" action="./">
                <input type="text" name="s" value="<?php if (isset($_GET["s"])) { echo htmlspecialchars($_GET["s"]);} ?>">
                <input type="submit" value="Go">


                if ($search_term != "") {
                    if (!empty($products)) {
                        echo '<ul class="products">';
                        foreach ($products as $product) {
                            echo get_list_view_html($product);
                        echo '</ul>';
                    } else {
                        echo '<p>No products were found matching that search term.</p>';




<?php include(ROOT_PATH . "inc/footer.php"); ?>

any ideas why?

The error I'm bumping into is quoted below:

Bummer! To place text inside a text input field, you should give it avalueattribute.

2 Answers


Take a look at the code at the top of the file. What PHP code you have in your value spot is correct (minus the conditional since it's not needed here). Take a look at line 5 of your code and you should have enough to know what to put inside the htmlspecialchars() function. I did the code challenge again and got it to work the way it's suppose to. Please keep in mind that while (in a real world setting) your code will work, the code challenge is looking for specific values and variables in order for it to pass you. Again please look at the top of your code and and think logically.

Hint: Has we dealt with the $_GET value or not and is there something set up to handle the $_GET value.

Trying to help you without giving you the answer. Look at your code carefully.


Gabi Udrescu
Gabi Udrescu
11,539 Points

Hi Shawn,

Thank you very much for your support! I nailed it and got the 12 points.

Another valuable lesson I've learned now is that if you have the feeling the answer is under your nose and you still don't see it, you should probably take a nap and sleep over the idea, because it's too late. Sometimes, late hours find me in front of my laptop taking code challenges and going through these amazing videos that are really catchy, despite my eyes almost closing down and my lack of concentration.

Eitherway, I'm back on track.