Forum Home
Press F1
 
Thread ID: 68180 2006-04-20 05:41:00 Mysql PHP quote mark problem Morgenmuffel (187) Press F1
Post ID Timestamp Content User
447901 2006-04-20 05:41:00 Ok I am doing a search of keywords in a database, and it works exactly how it should, provided the search term I have entered doesn't contain a quote mark, if the search term contails a quote mark the search returns zero results

Now the keyword is stored in the database n the following format

Gerti\'s

with the quote backslashed as above for the usual reasons

and below is the query i use to get it out

SELECT prod_ID
FROM product
WHERE prod_search_term like '%".$keyw."%'

which turns into the below when i enetr the search term Gerti's on my search page
SELECT prod_ID
FROM product
WHERE prod_search_term like '%Gerti\'s%'

(this has been echoed out just before the query is run, so that is what is sent to the MYsql server)

The problem is that I get zero results with the quote mark and there are matching records

I can get round the problem by entering Gerti and brings up all the products as it should, but i would prefer that queries with the quote mark in them worked
Morgenmuffel (187)
447902 2006-04-20 05:53:00 Could it be that the search is looking for exactly Gerti's (by accepting and "translating" the escaped quote) and can't match that with Gerti\'s which you say it is stored as? That is, should the quote be escaped in the database?

Youi coulld test that by doing a search for "Gerti\'s", by escaping the escape "\" . Would that be "Gerti\\\'s" ;)?
Graham L (2)
447903 2006-04-20 06:54:00 Hmm, I'm confused. In the actual record, you have the string: Gerti\'s i.e the backslash is in there.

I realise you have to escape the quote when doing an INSERT or SELECT.

You don't have that horrible PHP Magic Quotes feature going on, do you?
gibler (49)
447904 2006-04-20 10:20:00 Possibly magic quotes is on, I have a feeling it is, but it isn't something I can change as this is a working site and i am just adding a query,
Its got me baffled, nothing i try seems to work
Morgenmuffel (187)
1