Daniel Daniel - 1 year ago 95
HTML Question

Dont process html in value of input

I have a entry in my mysql table that contains html code (<p>Hello!</p>)
This show up fine when I want to display it (echo $entry) but when I place echo $entry in a textarea value= it executes the code instead of showing it.
Is there any way to stop the code executing and show the tags or convert to and from &lt ; &gt ;

Here is the code:

echo "<label for=\"details\">Details:</label><textarea id=\"details\" cols=\"60\" rows=\"10\" name=\"details\" value=\"" . $row["details"]."\"></textarea>";
Here is the entry:

Set to 0 (on)</ol>



Answer Source

You have to escape special characters. You can do that with htmlspecialchars().

What's more, You should not set a value to the textarea but rather write it in its content:

<?php /* some code here */ ?> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download