简体   繁体   中英

PHP-Mysql error with %

I wrote a very simple mysql line for my very simple search bar that searches keywords, but I ran through an error. (I have a feeling it's because of the length of the search)

$query = "SELECT * FROM entries WHERE name='%".$search."%' ";

works, but

$query = "SELECT * FROM entries WHERE desc='%".$search."%' ";

doesn't.

In the database, name has around 20 characters, and desc has around 700. I checked spelling and everything, it just outputs an error.

Does it not work because it has too many characters to scan through?

Thanks a lot (in advance)!

desc是mysql的关键字,需要用引号引起来,并且应使用LIKE而不是= ,并确保$search已被转义。

$query = "SELECT * FROM entries WHERE `desc` LIKE '%".$search."%' ";

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