3

I am pulling information from an SQL database to populate in a form using the PHP Echo command. One of the rows from the sql database includes HTML markup.

When pulling information and populating the form with the data, it will not pull the HTML markup in the form. It looks like this:

Example

Is there a way to have the full HTML markup populate in the form? This is the code I am currently using:

<input name="tag" type="text" id="tag" value="<?php echo $rows['tag']; ?>" size="30"/>
1
  • We can hardly answer to this if you don't show us how you populate that page. Commented Nov 14, 2015 at 20:27

3 Answers 3

1

Yes, you would need to use htmlentities() to show the entity code (which can be parsed by the browser as plain text) without actually forcing the browser to render the HTML.

echo htmlentities($rows['tag']);
Sign up to request clarification or add additional context in comments.

Comments

1

You need to escape the html code you want to use for populating the form using either htmlentities() or htmlspecialchars(). (See here)

It is in any case good and I would even say needed to use these functions whenever you echo values from a database or other untrusted source. This to prevent script injection, one of the major pitfalls in web development.

Comments

1

This should do it:

<input name="tag" type="text" id="tag" value="<?= htmlspecialchars($rows['tag']) ?>" size="30"/>

You are inserting a double quote into the input box like this:

value="<a href="http://www.google.com">Google</a>"

This should be encoded to html with the function htmlspecialchars

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.