apostraphe in MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

apostraphe in MySQL

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

addslashes($data) I believe.
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post 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\" ";
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post 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?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

To reverse addslashes(), you use [php_man]stripslashes[/php_man]()
User avatar
James M.
Forum Contributor
Posts: 119
Joined: Wed Mar 31, 2004 6:41 pm
Location: Tallahassee

Post by James M. »

thanks for the help all, ive succesfully fixed the problem
Post Reply