views:

148

answers:

3

When i am using mysql_real_escape_string on my unescaped strings the data in the database is storing with the backslashes which should not happen.

I have magic_quotes_gpc OFF not sure why this is happening. Any idea ?

Is there any setting in the mysql database which needs to be modified.

I am not using addslashes any where in the code. PHP language.

Please help.

+1  A: 

There are several variants of magic_quotes all of which are very invasive and cannot be overridden. I think its unlikely that that extra escaping is being done by the DBMS.

Have you checked what the data looks like before applying the mysql_real_escape_string() - I would bet its already escaped somehow.

C.

symcbean
Thank you for replying.But without mysql_real_escape_string the string is stored without the backslashes so " will get stored as " and \ will get stored as \ .Only when i use mysql_real_escape_string " get stored as \" and \ gets stored as \\Please help.
pks83
@pks283: that's because your data already was quoted by magic gpc. it's weird way to sanitize data. so the best solution is to turn off magic gpc and apply mysql_real_escape_string()
zerkms
magic quotes are not ON some other part of the code was adding slashes. Thanks @symcbean .
pks83
A: 

the answer is simple. There are no setting in the mysql database which needs to be modified. It is your code/settings.

Either you have magic_quotes_gpc on and it needs to be double-checked, or some of your code does another slashing.

Col. Shrapnel
A: 

stripslashes() is when the PHP directive magic_quotes_gpc is on (it's on by default), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form.

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Let us know when you use stripslashes, what does your input turn into. Does it get into required format. This is to check whether there is something going wrong with your input coming.

Since you have told that without applying mysql_real_escape_string your data gets stored without any blackSlashes... and after applying it you get blackslash... i personally feel double check your code whether you are applying addslashes some where.

Some questions...

  1. Does this happen only in this current function.
  2. Check your magic_quotes_gpc is on or off.
  3. Can you post a part of that function which is causing this problem.
Vinothbabu