-4

The below code will obviously search for similar results as the query variable but what is the SQL command to search for exact results and not "like"?

$query = "SELECT languages.language FROM languages WHERE language LIKE '%".$name."%'";
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Noah R
  • 5,287
  • 21
  • 56
  • 75

2 Answers2

5

have you tried the = operator and removing the % wild cards?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
1

Edit: Although I answered what you asked, it is worth pointing out, as others have said, that your code is vulnerable to SQL injection attacks :)

For exact matches:

$query = "SELECT languages.language FROM languages WHERE language ='".$name."'";

For non matches:

$query = "SELECT languages.language FROM languages WHERE language <> '".$name."'";
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148