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

Eduardo Garcia
Eduardo Garcia
4,571 Points

Stuck on Code Challange Escaping Output Review

My previous Discussion submission failed, so I'm summarizing it here quickly since the last one was pretty lengthy.

The task is to put the search term as the value of the search box when a user submits a search. My problem is that the challenge doesn't go through and when I preview, it gives me an access denied followed by a string of letters and numbers.

On the task, I echo an escaped search_term onto the value attribute of the first input tag right below the form tag. Am I doing something wrong or is TreeHouse having problems? I keep getting a Bummer! bar saying to add the attribute value to the input, but its already there.

The following is what I placed:

<form method="get" action="./">
                <input type="text" name="s" value="<?php echo htmlspecialchars($search_term);?>">
                <input type="submit" value="Go">
            </form>

2 Answers

I am having the same problem. Tried setting the value as both what you put and also htmlspecialchars($_GET["s"]), but same errors.

Hello Eduardo Garcia

the problem with your code if that you are always showing the $search_term even when it is empty(i.e when page first loaded)

SOLUTION: you should create a condition to verify where the array of products is empty like (if (!$products)) then apply the search value to the attribute value LIKE:

value = "<?php if(!$products){echo htmlspecialchars($search_term);}?>"

Hope this helps