php/mysql escaping backslashes
January 26, 2012 4:01 AM Subscribe
Php question:
mysql_real_escape_string is turning '\6' (and I assume any other \(number combination) into a single character '' where it's in my code, but not when the same string is passed through $_POST. Is this a behaviour of magic_quotes (currently on) or something else - and without the ability to change global php settings, what can I do about it?
The code I'm working with sets a hard-coded password when setting up a database (password changed, obviously):
$examplepass = mysql_real_escape_string("EXAMPLE_\6");
mysql_query("INSERT INTO Example_Users (
UserName,
Password,
) VALUES (
'example',
'$examplepass '
)");
Looking at the query before it's run, this is putting "EXAMPLE_" into the database.
Putting "EXAMPLE_\6" into the login form, then running it through mysql_real_escape_string, gives "EXAMPLE_\\6", which (obviously) doesn't match.
posted by monkey closet to computers & internet (6 answers total)
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
That should help with the matching but now with preserving backslashes in your content.
posted by missmagenta at 4:19 AM on January 26, 2012