Storing HTML in a database

This is a discussion on "Storing HTML in a database" within the PHP Forum section. This forum, and the thread "Storing HTML in a database are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 2nd, 2008, 13:27
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,340
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Storing HTML in a database

Just having a flick through a Wordpress database, it seems they store the post content with certain markup (such as <b>, <em>, <img> tags etc.) but not <p> (paragraph) tags, instead inserting these at 'runtime' with the use of PHP.

However, I've seen other CMS's simply store the complete HTML in the DB, then just output the chunk when required.

Is there any advantage of either? Surely the latter would save a little processing power?

Another Q - is it common to protect against (SQL) injection when you know the input is coming from an authenticated user? Say, when a logged in author is adding content to the DB? How would you do this if you need to preserve HTML tags?

Cheers for any advice
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 2nd, 2008, 14:09
CloudedVision's Avatar
Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 1,255
Blog Entries: 9
Thanks: 2
Thanked 40 Times in 40 Posts
Re: Storing HTML in a database

It seems to me that saving the complete HTML code will save processing power and such, I don't know why wordpress would save it without the <p> tags.

Actually, protecting against SQL injection is only half of it. You also need to protect against the user causing an SQL error because the close out the single quotes too early. So, yes it is common to do that.
__________________
Web Design And Development: Other Road Design | Problems with IE6?: KApp | My Blog: Only Nerds Allowed | Learning PHP? Lessons
Last Blog Entry: Hilarious Rapper (Jul 29th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
The Following User Says Thank You to CloudedVision For This Useful Post:
  #3  
Old Jul 2nd, 2008, 17:47
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,340
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Re: Storing HTML in a database

Quote:
Actually, protecting against SQL injection is only half of it. You also need to protect against the user causing an SQL error because the close out the single quotes too early. So, yes it is common to do that.
What's the best method for doing so? (I can't believe I didn't think of the user causing errors without intent!)
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 2nd, 2008, 18:44
CloudedVision's Avatar
Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 1,255
Blog Entries: 9
Thanks: 2
Thanked 40 Times in 40 Posts
Re: Storing HTML in a database

It depends. If magic_quotes is on, you don't need to do anything. (I usually insert a line in the script to turn it off, it can mess quite a lot of things up) If its off, mysql_escape_string() works nicely.

Just out of curiousity, whats this big project you seem to be doing? A CMS or something of the like?
__________________
Web Design And Development: Other Road Design | Problems with IE6?: KApp | My Blog: Only Nerds Allowed | Learning PHP? Lessons
Last Blog Entry: Hilarious Rapper (Jul 29th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
The Following User Says Thank You to CloudedVision For This Useful Post:
  #5  
Old Jul 2nd, 2008, 20:15
Aso's Avatar
Aso Aso is offline
Moderator

SuperMember
Join Date: Oct 2007
Location: UK
Posts: 1,340
Blog Entries: 2
Thanks: 11
Thanked 49 Times in 46 Posts
Re: Storing HTML in a database

Quote:
Originally Posted by CloudedVision View Post
If magic_quotes is on, you don't need to do anything. (I usually insert a line in the script to turn it off, it can mess quite a lot of things up) If its off, mysql_escape_string() works nicely.
Cheers for the tip CV

Just wondered if mysql_escape_string was sufficient - having looked it up, the function's now deprecated and mysql_real_escape_string should be used instead.

Quote:
Originally Posted by CloudedVision View Post
Just out of curiousity, whats this big project you seem to be doing? A CMS or something of the like?
Aha! Yes, this is quite new to me (I've worked with open-source kits before, but never really tackled the DB side of things head on).

For this project (a bathroom showcase site) I really needed something quite specific and dead simple

Luckily I've also got Mr Ullman's 'PHP and MySQL for Dynamic Websites' SE which has really helped me out, but it's not quite the same as some dedicated advice @ WF
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 2nd, 2008, 20:31
CloudedVision's Avatar
Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 1,255
Blog Entries: 9
Thanks: 2
Thanked 40 Times in 40 Posts
Re: Storing HTML in a database

Quote:
Originally Posted by Aso View Post
Just wondered if mysql_escape_string was sufficient - having looked it up, the function's now deprecated and mysql_real_escape_string should be used instead.
shoot. I knew it contained the word "real" in it.

thanks for the correction
__________________
Web Design And Development: Other Road Design | Problems with IE6?: KApp | My Blog: Only Nerds Allowed | Learning PHP? Lessons
Last Blog Entry: Hilarious Rapper (Jul 29th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching HTML And Storing josephman1988 Other Programming Languages 0 Feb 18th, 2008 13:25
[SOLVED] Help with HTML form to database (mysql/php)! skuliaxe PHP Forum 7 Jan 20th, 2008 00:41
How to connect the microsoft access database using HTML page mazenbluee Databases 5 Nov 21st, 2007 06:49
php/mysql database fields into html list/menu csun PHP Forum 4 Jul 27th, 2007 16:04
storing lists of friends keyboardcowboy Website Planning 0 May 22nd, 2007 19:14


All times are GMT. The time now is 17:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42