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 Build a Basic PHP Website (2018) Enhancing a Form Escaping Output

John Gianniny
John Gianniny
13,012 Points

How to employ Escape Output here...

I think I am way off on this one; please help.

views_listing_edit.php
<?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 echo htmlspecialchars($_POST['$listing_name']); ?>">
                </td>
            </tr>
            <tr>
                <th>
                    <label for="link">Link</label>
                </th>
                <td>
                    <input id="link" name="link" value="<?php echo htmlspecialchars($_POST['$listing_link']); ?>">
                </td>
            </tr>
            <tr>
                <th>
                    <label for="description">Description</label>
                </th>
                <td>
                    <textarea id="description" name="description"><?php echo htmlspecialchars($_POST['$listing_description']); ?></textarea>
                </td>
            </tr>    
        </table>
        <input type="submit" value="Save">
    </form>

</body>
</html>

1 Answer

You were mostly correct, the problem is that the variables you are escaping are coming from the required script at the top, not from the POST array

This:

<input id="name" name="name" value="<?php echo htmlspecialchars($_POST['$listing_name']); ?>">

Should become this:

<input id="name" name="name" value="<?php echo htmlspecialchars($listing_name); ?>">

once you've changed all 3 of these it should pass

John Gianniny
John Gianniny
13,012 Points

Thank you Conner! The explanation is really helpful as well.