Why does mysql db stop saving when it detects a single qoute even if I escape them?

3 replies
Code:
$firstname=mysql_real_escape_string("joh'n");
$middlename=mysql_real_escape_string("do'e");
$lastname=mysql_real_escape_string("smit'h");
$home_address=mysql_real_escape_string("addres's") ;

UPDATE `users`
SET
`firstname`='$firstname',`middlename`='$middlename ',`lastname`='$lastname',`home_address`='$home_add ress'
WHERE `user_id`=$userid
What will be saved are:
joh
do
smit
addres
All other characters can be saved but this single quote, can somebody tell me why? Thank you
#detects #escape #mysql #qoute #saving #single #stop
  • Profile picture of the author Big Squid
    echo out the query.

    It'll read

    UPDATE 'user' SET 'firstname' = '"joh'...and so on...
    {{ DiscussionBoard.errors[6011088].message }}
  • Profile picture of the author KirkMcD
    Where/how are you checking what has been saved?
    {{ DiscussionBoard.errors[6012238].message }}
  • Profile picture of the author Earnie Boyd
    mysql_real_escape() string is supposed to escape ' with a \ so you should have in $firstname something like "joh\'n" but that may be interfered by the client encoding. You may need to use mysql_client_encoding() before the mysql_real_escape_string() call.

    Also make sure magic quotes are off.
    Signature
    {{ DiscussionBoard.errors[6013481].message }}

Trending Topics