General Question

sethunath's avatar

Magic quotes gpc and mysql_real_escape_string adds multiple slashes in my input?

Asked by sethunath (2points) January 3rd, 2011

magic quotes gpc and mysql_real_escape_string adds multiple slashes in my input . How do I unescape my input ? Do I have to call stripslashes twice ?

Observing members: 0 Composing members: 0

3 Answers

koanhead's avatar

It might help to answer if we had some idea what the strings look like that you are trying to clean up.
Do you need to strip all slashes from the string? Am I correct in assuming that this is a mysql query string that you are about to send to the database engine?
In your place I would probably cook up a regex to get the job done.

funkdaddy's avatar

Check out the notes on the php.net documentation along with the user contributed notes.

http://us2.php.net/manual/en/function.mysql-real-escape-string.php

Specifically from the notes

Note:

If magic_quotes_gpc is enabled, first apply stripslashes() to the data. Using this function on data which has already been escaped will escape the data twice.

Which would mean basically use stripslashes() before inserting the data (and before mysql_real_escape_string()).

The user contributed notes have several alternatives that accomplish the same in a more complete way.

Good luck with it.

camertron's avatar

I ran into an issue once where I was saving an escaped string to the database from a textarea in a form. The user would submit the form and the data would be escaped and saved in the database. The user would then go to edit this string again (it was their bio) and be shown escaped text in the textarea. If they submitted it again, it would get double-escaped and saved to the database. I had to call stripslashes() twice to get it to look normal. They key (of course) was to unescape the string before it’s put into the textarea.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther