Search code examples
phpmysqlsearchmatch-against

MATCH AGAINST unknown column


I have problems with my searching method, I'm using MATCH AGAINST because it's better than LIKE. For example I have a database full of cities and when I type a city name (for example Moscow) in the input field, there is an error "Unknown column 'Moscow' in 'where clause'". I have two columns in my database, city_id and city_name

enter image description here

My sql query looks like this

"SELECT city_name FROM default_cities WHERE MATCH(city_name) AGAINST($city)"

If someone have any suggestions I'll be appreciated :)


Solution

  • "SELECT city_name FROM default_cities WHERE MATCH(city_name) AGAINST('$city')"
    

    Use quotes for $city

    EDIT

    Don't forget to escape it. (for ex. "l'amour")