Jump to content

Storing words containing apostrophes in database and then displaying them


Kay1021

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

 

Thanks

 

 

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.