paracaudex
paracaudex

Reputation: 3

HTML tags in mysql text field

I'm creating a database with what I anticipate will be a long (perhaps several paragraphs for some tuples) attribute. I'm assigning it text instead of varchar. I have two questions:

  1. Should I give a maximum value for the text field? Is this necessary? Is it useful?
  2. Since the contents of this field will be displayed on a website in HTML, do I need to include paragraph tags for paragraph formatting when I enter records into mysql?

Upvotes: 0

Views: 2020

Answers (4)

Your Common Sense
Your Common Sense

Reputation: 157989

text field nas no length parameter.
enter whatever you with as long as it displays correctly

Upvotes: 0

zellio
zellio

Reputation: 32524

  1. Not really, define as text.
  2. If you want to display text in HTML with formatting you will either have to build the HTML tags into the text in the database or parse before printing and add them then.

Upvotes: 3

Andy
Andy

Reputation: 17791

  1. No define it as text or mediumtext
  2. If the data will be output as HTML, store HTML tags

Upvotes: 1

Dustin Laine
Dustin Laine

Reputation: 38543

1) I do not give max length for fields that I place HTML in, as it is variable and could always grow longer. 2) I would place all HTML in the field, but it depends on if you want to do that extra step in your application.

NOTES: Always HTML encode your HTML data before inserting to database.

Upvotes: 0

Related Questions