PDA

View Full Version : Backslashes before apostrophes and quotes


mlmorg
12-12-2007, 12:57 AM
I moved my host from dreamhost to godaddy and now I get backslashes before apostrophe's and quotes when I send things to the database.

If I edit something more than once, the backslashes grow as well. So if I edit something 3 times that has an apostrophe in it, there will be three \\\ backslashes before the apostrophe.

What's going on here?

Do I need to do some sort of .htaccess edit?

Also, old things don't seem to have acquired backslashes...it's only new things that I insert into the database that get the backslashes.

CFMaBiSmAd
12-12-2007, 01:14 AM
The problem is the magic quotes settings - http://php.net/magic_quotes

You either need to turn them off in php.ini or a .htaccess file or your code needs to detect if they are on and remove any existing slashes before your own are added when inserting data into the database.

The magic_quotes were yet another thing that the php language did that the programmer should have been doing himself, and only when he wanted them.

Majoracle
12-12-2007, 01:17 AM
The easy way to get rid of all those slashes is to pass the string through stripslashes() when you display it. That's PHP101.

felgall
12-12-2007, 01:18 AM
The easy way to get rid of all those slashes is to pass the string through stripslashes() when you display it. That's PHP101.

Yes but you shouldn't have to run it through twice which is what would be required if both magic quotes is enabled as well as using addslashes.

mlmorg
12-12-2007, 01:41 AM
Ok thanks very much. I didn't know about magic quotes.

Just turned it off in the php.ini