TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   how do you insert html into your database? (http://www.talkphp.com/general/3354-how-do-you-insert-html-into-your-database.html)

sarmenhb 09-12-2008 10:19 PM

how do you insert html into your database?
 
the html code contains symbols how do you insert that into mysql database witout getting errors?

for example

if i wanted to insert this peice of code into a table how would i insert it witout getting errors :(

Code:

<ul>
<li class="listing">first</li>
<li>second </li>
<li> third</li>
<li class="last">fourth</li>
</ul>


sarmenhb 09-12-2008 10:33 PM

nm, i figured it out lol

for those of you who want to know how to do it :)
what i did was

i put a textarea box on the page to insert the html into (for testing)
and i did
Code:

$code = urlencode($_POST['txt_code']);
mysql_query("insert into tablename values(null,'$code'");

what that does is it places a buncha %'s into the html code where its needed

then to output it

i did

while($row = mysql_fetcH_assoc--- bla bla all that stuff then
echo urldecode($row['code']);

BJ Duncan 09-13-2008 11:51 AM

Thanks for this info. I was using the htmlentities() and the html_decode_entity() functions.

What is the difference between the htmlentities function and the urlencode functions?

xenon 09-13-2008 12:08 PM

urlencode just encodes characters that are URL-incompatible. Practically, you would use htmlentities on any output that goes on the screen and is going to be viewed by users. urlencode assumes encoding of URL parts only.


All times are GMT. The time now is 05:04 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0