Page 1 of 1

How do I query a database WHERE a string has a ' in it?

Posted: Mon Apr 21, 2003 4:37 pm
by 3dron
I am comparing some titles against a database to get their ID number.

It works fine for all except if the sting has an apostrophe.

Is there an escape character I can ereg_replace into the string?

RR

Posted: Mon Apr 21, 2003 4:47 pm
by Rob the R
Rather than use regex patterns, try the PHP functions addslashes() or mysql_escape_string()

Posted: Mon Apr 21, 2003 8:00 pm
by Jade
I found it also works if you give it an exta '. For instance if the title is:

Who's that girl?

Then you could just have it add an extra ' changing it to:

Who''s that girl?

And then it gets it just fine....just a thought!!!


Jade

Posted: Mon Apr 21, 2003 10:11 pm
by McGruff
addslashes() or mysql_escape_string() - and stripslash() on the way out.

On the way in to a db, I also like to htmlspecialchars() anything that will later be displayed in a browser or form field. Blocks all kinds of nastiness.

Posted: Wed Apr 23, 2003 4:07 pm
by Jade
Lol,

your reply makes me sound stupid!!! Oh well, taught me something new as well...can you tell i'm still pretty new at this?? Hehe, and i've been at it for over a year now. Go figures...

Jade
:lol: