Page 1 of 1
apostraphe in MySQL
Posted: Mon May 17, 2004 1:53 pm
by James M.
Hi, I have come across a problem in MySQL when entering data that contains an apostraphe[ ' ] into a column. I am wondering is there any way to allow a user to enter data containing an apostraphe into a column? Thanks for any help ahead of time.
Posted: Mon May 17, 2004 2:06 pm
by feyd
addslashes($data) I believe.
Posted: Mon May 17, 2004 2:08 pm
by leenoble_uk
You need to escape it (Put a backslash in front of it)
SET my_column = "Pete''s Stuff"
There's a PHP command called addslashes which does just this for you.
Of course if this statement was in a PHP string you would have to escape the escapement.
$sql = "UPDATE mytable SET my_column = \"Pete\\''s Stuff\" WHERE something=\"$something\" ";
Posted: Mon May 17, 2004 7:13 pm
by James M.
so how would i escape the escapement if i am not able 2 manually escape it since im guessing addslashes would not escape the escapement for me, especially since most people coming to a site will forget to add the backslash when entering data?
Posted: Mon May 17, 2004 8:18 pm
by jason
To reverse addslashes(), you use [php_man]stripslashes[/php_man]()
Posted: Mon May 17, 2004 8:31 pm
by James M.
thanks for the help all, ive succesfully fixed the problem