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.
|
|
|
|
|
![]() |
||
Storing HTML in a database
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
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)
|
|
|
|
#2
|
||||
|
||||
|
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)
|
| The Following User Says Thank You to CloudedVision For This Useful Post: | ||
|
#3
|
||||
|
||||
|
Re: Storing HTML in a database
Quote:
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
|
#4
|
||||
|
||||
|
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)
|
| The Following User Says Thank You to CloudedVision For This Useful Post: | ||
|
#5
|
||||
|
||||
|
Re: Storing HTML in a database
Quote:
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:
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)
|
|
#6
|
||||
|
||||
|
Re: Storing HTML in a database
Quote:
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)
|
![]() |
| Thread Tools | |
|
|
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 |