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 trialMarko Vojvodic
32,207 Pointshow can i solve this challenge?
how can i solve this challenge?
<?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($_POST["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($_POST["link"]); } ?>">
</td>
</tr>
<tr>
<th>
<label for="Description">Description</label>
</th>
<td>
<textarea id="description" name="description"><?php if(isset($listing_description)) { echo htmlspecialchars($_POST["description"]); } ?></textarea>
</td>
</tr>
</table>
<input type="submit" value="Save">
</form>
</body>
</html>
3 Answers
Kourosh Raeen
23,733 PointsYou just need to use the htmlspecialchars() function, as discussed in the video:
<?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($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>
</body>
</html>
Bob McCarty
Courses Plus Student 16,618 PointsMy code did not display, I am trying again.
<!-- line 13 -->
<input id="name" name="name" value="<?php echo htmlspecialchars($listing_name, ENT_COMPAT, 'UTF-8'); ?>"
<!-- line21 -->
<input id="link" name="link" value="<?php echo htmlspecialchars($listing_link, ENT_COMPAT, 'UTF-8'); ?>">
<!-- line29 -->
<textarea id="description" name="description"><?php echo htmlspecialchars($listing_description, ENT_COMPAT, 'UTF-8'); ?>
Marko Vojvodic
32,207 PointsThanks very much!
Bob McCarty
Courses Plus Student 16,618 PointsBob McCarty
Courses Plus Student 16,618 PointsHi, Use htmlspecialchars() with the args , ENT_COMPAT, 'UTF-8'. I suggest the following;
<!-- line 13 --> <input id="name" name="name" value="<?php echo htmlspecialchars($listing_name, ENT_COMPAT, 'UTF-8'); ?>">
<!-- line21 --> <input id="link" name="link" value="<?php echo htmlspecialchars($listing_link, ENT_COMPAT, 'UTF-8'); ?>">
<!-- line29 --> <textarea id="description" name="description"><?php echo htmlspecialchars($listing_description, ENT_COMPAT, 'UTF-8'); ?> </textarea>