Jump to content

Storing words containing apostrophes in database and then displaying them


Recommended Posts

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





Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.