Re: addslashes & stripslashes
| From: | Marek Kilimajer | Date: | Wed, 28 Jan 2004 12:50:49 +0000 |
| Subject: | Re: addslashes & stripslashes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176032@lists.php.net to get a copy of this message | ||
Will wrote:
I'm a little confused with these functions. How I here you ask. Well I thought I understood what they were for: Escaping characters that might cause a problem when you enter your data into a database query. i.e. \ ' " Anyway what is confusing me is, say I have a string which contains an ' e.g: that's mine. I would use addslashes so that the query wouldn't upset mysql when it is entered. Viewing the data entry via phpmyadmin the data is displayed as: that's mine (not: that\'s mine) Meaning that when I extract the data from the database I need to use stripslashes returning the string to: that's mine. (I thought that perhaps phpmyadmin striped the slashes when displaying the data.) However recently I encrypted some data which I stored in the database. The string contained a \ which I added slashes to when entered in to the database. But as the database appears to strips the first slash off the double slash automatically. Upon retrieving the data and strip the slashes off it, my data is now corrupt as there weren't double slashes it was just a single (like it was supposed to be) and that got removed by the function instead of the extra one. As I haven't had any data that contains a \ in it before I've never noticed it's not made any difference before. So Does this basically mean that there is no point using stripslashes on the data you extract from the database.True. "that's mine" is already stored in the database as "that's mine" (w/o the backslash), and the database returns this. If you have magic_quotes_runtime on, php will run addslashes on the database output, but it's usualy off. Remember that the backslashes are to escape characters with special meaning (such as end of a string), but are not part of the actual string. They simply say the next character should be treated literaly.
Or am I just being an idiot :-) Thanks Will _____ I've stopped 46,346 spam messages. You can too! One month FREE spam protection at www.cloudmark.com <http://www.cloudmark.com/spamnet?v1> <http://www.cloudmark.com/spamnet?v1> Cloudmark SpamNet - Join the fight against spam!