Forum Moderators: coopster

Message Too Old, No Replies

input to database

         

electricocean

7:10 pm on Jun 25, 2005 (gmt 0)

10+ Year Member



Is there a way to escape charaters from a post before inputting it into the database?

like: <br> to \<br\>

electricocean

coopster

7:23 pm on Jun 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mysql_real_escape_string [php.net]
addslashes [php.net]

ergophobe

10:24 pm on Jun 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, those functions won't addslashes in the case mentioned and slashes won't really help you there anyway - they're not necessary.

So, three possibilities

1. You chose a bad example, and you really want to escape quotes and slashes, then the functions mentioned by coopster will help.

2. You want to display HTML as text so that it looks like <b>this</b> and not like this. In that case you want the functions

htmlentities()
htmlspecialchars()
html_entity_decode

3. You think there is a problem with storing HTML in a database and it needs to be escaped. In that case, just relax, no worries. You will need to add slashes as coopster mentioned to escape the quotes, just as you would in any text, but you don't need to escape the HTML per se. So in other words

<html><body>This here is just fine</body></html>

<html><body class="bodyclass">This is a problem</body></html>
As for this line of text with no html, it's a problem too (apostrophe)
And this line has a "problem" of its own (double quotes).