Avatar of anumit
anumit asked on

Store HTML code in database

Hi

I am working on creating a website, which will generate web pages dynamically. HTML would be stored in database and would be modified according to who has logged in and then displayed to users.

Please help suggest how to store HTML code in database?
I am running SQL Server 2005.

Thanks
Anu
HTMLASPMicrosoft SQL Server

Avatar of undefined
Last Comment
anumit

8/22/2022 - Mon
brad2575

Are you asking how to put it into the database?  Or just asking how to set up the database to store it?

You can set the database field to be text and just save the HTML into the field in the database.

Then when you want to display this data, query the database, and just write the field from the database to the screen.
ASKER
anumit

hi,
i am asking to put it into the database.
i am not sure if the tags and special characters create problems when stored in database.

brad2575

Depending on how you insert them into the databse they should not cause problems.  If you just copy/past it into the filelds in the database table it should be fine.

If you are worreid about special characters use the HTML code for the characters you are worried about so when you display them on the screen it will display the character but just using the HTML code to do so.

If you are using scripts or something to insert the data into the database, this is where it gets tricky.  Not so much with most "special characters" but using single and double quotes can cause issues.

If you are not going to be inserting the data often into the database then I would say just create the HTML in a file and copy/paste it into the database.

If you are going to use scripts to do so you would need to create a function to update the HTML code so that the quotes are escaped (allows you to insert them properly).

If you are going to use scripts to do it let me know and I can provide a code example to insert the escape characters for the single/double quotes.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
anumit

Hi,
I am using asp to insert HTML into the table. It would be great if you could provide some sample code to escape characters.
Thanks.
Dux11

I like to call stored procedures and add parameters to the object instead of handling double quotes etc in the sql string as I find it handles the special characters plus depending on the actions can save bandwith (probably not here for a single insert though).

Didn't want to interupt as Brad is already helping you out but thought I would add my personal preference for thought.

Good luck
ASKER CERTIFIED SOLUTION
brad2575

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
anumit

It works fine.
Thanks for the code.

Dux11, I will also try your method.

Thanks for your help.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.