Hello PHP experts how can you detect ' character in your search field?
Because every time I input the word hilgard's it returns an error I think because of the character '. This is the error

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';'., SQL state 37000 in SQLExecDirect in D:\wamp\www\Online Library\opac.php on line 76
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';'.

tnx in advance.

What happens is, the query ends when it encounters ' in hilgard's. Escape it with \.
Eg.

'SELECT *
FROM `table3`
WHERE name LIKE '%hilgard\'s%'

To escape the single quote, you can use addslashes (or mysql_real_escape_string if your database is mysql). Or
You can use double quotes.

"SELECT *
FROM `table3`
WHERE name LIKE '%hilgard's%"

:) Cheers,
Naveen

Hello nav33n i've tried your code

"SELECT *
FROM `table3`
WHERE name LIKE '%hilgard's%"

but still it returns an error

hmm.. weird.. Did you try the other option ? escaping ' ?

"SELECT *
FROM `table3`
WHERE name LIKE '%hilgard\'s%'"
"SELECT *
FROM `table3`
WHERE name LIKE '%hilgard\'s%"

Oh right ! I think I need to sleep for some more time! ;)

Solved it. I use $exp = str_replace("'", "", $exp); BTW Thanks to the two of you..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.