简体   繁体   中英

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

在此处输入图片说明

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 :)

If you posted your complete code, we would be able to tell you that you need to put single quotes against $city . You should be using prepared statements. I'll also go off on a limb and guess you're using mysql_ functions. Those are deprecated and you should be using PDO or mysqli_

"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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM