Forum Moderators: coopster
' becomes \' - correct and will work
\' becomes \\' - incorrect and errors
Am I doing something wrong or missing something here?
It may be just that I am tired.
Thank you
Is magic_quotes_gpc enabled? Is there another function you're using on that data that may be borking the string? One thing to do is to echo htmlentities($yourvar) after the submit so you make sure any non-display characters are sneaking in.
Sean
It takes the output from the form
$_REQUEST['info']
it does mysql_real_escape_string on it and creates the sql.
If I echo it at this point I am getting
"INSERT into information VALUES info='bob\\'s'"
I am glad this is odd. php version 4.3.10
Also if I submit it with a single backslash in it, the backslash disappears.
magic quotes is off.
I will take a close look at my code and make sure I am not doing anything odd and that it is in the right order.
Also try doing addslashes() instead of mysql_escape_string() just to see if you can reproduce the behavior. If you can't at least you know it's a mysql issue and it will help you zero in.
Sean
$info - addslashes($_REQUEST['info']); // info=bob's with no \' escaping characters. Try to insert it that way
Yes it works for the \' because it is already commented but would then fail for ex'amp\'le
In theory I should get the form output, run it through mysql_real_escape_string and then insert it into the database. For some reason this isn't working. The question is why.
I am going to rewrite the function.
Thanks for all your help.
Sean
I found that the problem involved preg_replace.
All content going into preg_replace comes back with half the number of backslashes in it.
So as a work around I added the line
$value = str_replace("\\","\\\\",$value);
which basically means replace every backslash with two backslashes.
Everything is now sweet.
If anyone knows a better solution feel free to let me know.