Hello,
While i have been working on a few PHP scripts i have come across something and i cannot figure out why it is doing it, hopefully you may be able to tell me.
When a form is submitted i have always used the following code to protect the mysql queries from sql injection and to strip any tags that have been entered:
$data=mysql_real_escape_string(strip_tags($_POST['data']);
The data variable is then passed through a mysql query and then i echo out a message like this.
echo "The data you entered, ".$data.", was successfully added to the database.";
The problem is this... When the data is echoed out, if the data contained a ' character then there is 3 backslahes before it.
For example is a user entered: Eddie's code
The message would say: The data you entered, Eddie\\\'s code, was successfully added to the database.
I think that the ' character is being protected by a backslash and then both those characters are being protected so therefore it results in 3 backlashes and a ' character.
When i remove the SQL protection (mysql_real_escape_string(strip_tags($_POST['data'])) then the data is passed through the query correctly without trouble...
After all of that what i really want to know is, do mysql queries now protect themselves form SQL injection?
I don't know which verison PHP the server i have my script hosted on it, but i would just like to know why this is and whether it is safe to remove all the SQL protection as the mysql quries execute the code with no trouble even when a ' character is used.
Sorry for the essay haha,
Thanks everyone for you time in helping me
Eddie
##Edit##
When a user submits a textfield with a ' characters in it, is that characters escaped using a backslash?