Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database for Content - OK to store HTML?

Basic question is - is it safe to store HTML in a database if I restrict who can submit to it?

I have a pretty simple question. I provide video tutorials and other content. Without spending months writing a proper BBCode parser, I would need to store the HTML so I can have it look exactly the way I want when I grab it from the database.

Basically I plan to store all information in the database about a tutorial series and each episode. I would like to have some formatting for the descriptions for both so I can add multiple paragraphs, ordered and unordered lists, links to required resources, and so on.

I am using PHP and creating my own database. I am using phpMyAdmin to store the information in the table right now. I will use a user with read only rights when I pull the information in the PHP code.

What is the best way to do this? Thank you!

like image 444
Ethosik Avatar asked Jan 30 '13 14:01

Ethosik


People also ask

Can we use database in HTML?

It happens on server, which is where the website is hosted. So, in order to connect to the database and perform various data related actions, you have to use server-side scripts, like php, jsp, asp.net etc. In order to insert new data into the database, you can use phpMyAdmin or write a INSERT query and execute them.

How do I save an HTML database in SQL?

you can save the html codes just like text. You can use varchar(max) type column to save the html code in table. Display the code is depending the browser. But if you use nvarchar type that will cause problems in display.


1 Answers

Like others have pointed out there's nothing dangerous about storing HTML in the DB. But when you display it you need to know the HTML is safe. Seeing as you're the only one editing the HTML I see no problem.

However, I wouldn't store HTML at all. If all you need are headings, paragraphs, lists, links, images etc I'd say Markdown is a perfect fit. The benefit with Markdown is that it looks just like normal text (ie you could send your articles as e-mails or save them as txt-documents), it takes up a lot less space than HTML and you don't have to change it once HTML gets updated.

http://michelf.ca/projects/php-markdown/

like image 57
powerbuoy Avatar answered Sep 22 '22 13:09

powerbuoy