• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

MySQL and mysql_escape_string syntax

I am performing a mysql query. Need the correct syntax so that input can have non standard characters in search (ie. apostrophe). For example, if searching John Doe's Company. The apostrophe is causing errors. Here is my code which does not work and need the % around the search term for wildcard search.
$trade_name = "%".$trade_name."%"; 
$sql = "SELECT * from doctors WHERE trade_name LIKE" . mysql_escape_string($trade_name) . "";
// also tried this
$sql = 'SELECT * from `doctors` WHERE `trade_name` LIKE \''.mysql_escape_string($trade_name).'\' LIMIT \''.$set_limit.'\', \''.$limit.'\'';

Open in new window

1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you miss the quotes:
$sql = "SELECT * from doctors WHERE trade_name LIKE '%" . mysql_escape_string($trade_name) . "%' ";

Open in new window

pdheadyAuthor Commented:
thanks that worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now