Kay1021 Posted May 14, 2009 Share Posted May 14, 2009 This may seem like a stupid question...and i know i've done it before...but i can't for the life of me remember how and i can't seem to find any help searching google. When you have a form and the user input something and the word contains a ' (example: Sue's) How do you deal with storing "Sue's" into the database and then displaying again Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158078-storing-words-containing-apostrophes-in-database-and-then-displaying-them/ Share on other sites More sharing options...
Ken2k7 Posted May 14, 2009 Share Posted May 14, 2009 You mean mysql_real_escape_string? Quote Link to comment https://forums.phpfreaks.com/topic/158078-storing-words-containing-apostrophes-in-database-and-then-displaying-them/#findComment-833855 Share on other sites More sharing options...
sqlnoob Posted May 14, 2009 Share Posted May 14, 2009 Sue/'s or Sue\'s can't remember for sure if it was addslash or backslash Quote Link to comment https://forums.phpfreaks.com/topic/158078-storing-words-containing-apostrophes-in-database-and-then-displaying-them/#findComment-833905 Share on other sites More sharing options...
Kay1021 Posted May 14, 2009 Author Share Posted May 14, 2009 ok it's mysql_real_escape_string() and that's what you use to prevent SQL injection too right? But now i have another situation before I was taking the name the user inputted and removing any spaces and that would become the reference name But if the user enters "Sue's"....later my reference won't work because of the '.... How would I take the name i gathered from the user....use is as $name keeping the apostrophe or other symbols....and then also use it as $reference but removing any spaces and/or symbols? Quote Link to comment https://forums.phpfreaks.com/topic/158078-storing-words-containing-apostrophes-in-database-and-then-displaying-them/#findComment-834298 Share on other sites More sharing options...
Brian W Posted May 14, 2009 Share Posted May 14, 2009 is backslash, example: Sue\'s forward slash won't hurt anything mysql_real_escape_string() will prevent sql injection, correct. To remove spaces and non letter characters, use: $string = preg_replace('/\s+/', '', $name);//get rid of spaces $reference = preg_replace("/[^a-zA-Z\s]/", "", $string);//get rid of anything but letters. Quote Link to comment https://forums.phpfreaks.com/topic/158078-storing-words-containing-apostrophes-in-database-and-then-displaying-them/#findComment-834318 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.