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 Integrating Validation Errors Escaping Output

Alexander Hepburn
Alexander Hepburn
14,613 Points

escaping output

I can't get this code to work, please help, thanks.

<?php require_once("controllers_listing.php"); ?><html> <body>

<h1>Edit Listing</h1>

<form method="post">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input id="name" name="name" value="<?php if (isset($listing_name)) { echo htmlspecialchars($listing_name); } ?>">
            </td>
        </tr>
        <tr>
            <th>
                <label for="Link">Link</label>
            </th>
            <td>
                <input id="link" name="link" value="<?php if (isset($listing_name)) { echo htmlspecialchars($listing_name); } ?>">
            </td>
        </tr>
        <tr>
            <th>
                <label for="Description">Description</label>
            </th>
            <td>
                <textarea id="description" name="description"><?php if (isset($listing_name)) { echo htmlspecialchars($listing_name); } ?></textarea>
            </td>
        </tr>    
    </table>
    <input type="submit" value="Save">
</form>

</body> </html>

3 Answers

Alex Heil
Alex Heil
53,547 Points

hey alexander, actually you're doing it quite good in your example but you always use the listing_name variable on all elements instead of the right one's (probably a copy/paste thing).

originally the second one would be listing_link and the third one is listing_description

if you change this your code will pass. hope that helps ;)

here's how the correct full code output should look at the end:

<h1>Edit Listing</h1>

<form method="post">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input id="name" name="name" value="<?php echo htmlspecialchars($listing_name); ?>">
            </td>
        </tr>
        <tr>
            <th>
                <label for="Link">Link</label>
            </th>
            <td>
                <input id="link" name="link" value="<?php echo htmlspecialchars($listing_link); ?>">
            </td>
        </tr>
        <tr>
            <th>
                <label for="Description">Description</label>
            </th>
            <td>
                <textarea id="description" name="description"><?php echo htmlspecialchars($listing_description); ?></textarea>
            </td>
        </tr>    
    </table>
    <input type="submit" value="Save">
</form>
Alex Heil
Alex Heil
53,547 Points

you only changed it in the isset part (you wouldn't need this part at all) for this task ;)

the important part is at the end with the htmlspecialchars - there you still always output listing_name

hope that helps ;)

Alexander Hepburn
Alexander Hepburn
14,613 Points

I really can not get this right, please help :D

Alexander Hepburn
Alexander Hepburn
14,613 Points

'''php

<?php require_once("controllers_listing.php"); ?>

<h1>Edit Listing</h1>

<form method="post"> <table> <tr> <th> <label for="name">Name</label> </th> <td> <input id="name" name="name" value="<?php if (isset($listing_name)) { echo htmlspecialchars($listing_name); } ?>"> </td> </tr> <tr> <th> <label for="Link">Link</label> </th> <td> <input id="link" name="link" value="<?php if (isset($listing_link)) { echo htmlspecialchars($listing_name); } ?>"> </td> </tr> <tr> <th> <label for="Description">Description</label> </th> <td> <textarea id="description" name="description"><?php if (isset($listing_description)) { echo htmlspecialchars($listing_name); } ?></textarea> </td> </tr>
</table> <input type="submit" value="Save"> </form> ''' I change my code buy it still doesn't work.