MySQL auto stripslashes?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

MySQL auto stripslashes?

Post by php_wiz_kid »

In a common files used at the top of every page I have a little script that add slashes to every $_POST, $_GET, and $_COOKE variable. This is similar to what's used in PHPBB. My question is does MySQL automatically remove the salshes on insert into the database? When I step through the code it seems that the slashes stay right up to the moment it gets inserted. Should I worry about this or should I just let it do its thing?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It expects the information to be slashed, because of delimiting characters it uses, so yes, it stripslashes()
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

Should the data in the database be slashed or is that something I shouldn't worry about?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the data stored will not be slashed unless you do a double addslashes, which just wastes bytes.. :P
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

Alright, thanks, that's all I needed to know! :D
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Note that it is probably a better idea to use mysql_real_escape_string() rather than addslashes().
Post Reply