简体   繁体   English

如何在MySQL中使用'LIKE'运算符使用$ _GET的值检索查询结果

[英]How to use 'LIKE' operator in MySQL to retrieve result of a query using the value of $_GET

I would like to query my database so that it shows me the result of the query based on my PHP's superglobal $_GET. 我想查询数据库,以便向我显示基于PHP的超全局$ _GET的查询结果。 I have tried this: 我已经试过了:

LIKE '%".$_GET["name"]."%'"

AND

LIKE '%{$_GET["name"]}%' 

However, it was in vain. 但是,它是徒劳的。 Can anyone help me with this? 谁能帮我这个?

This is my php code: 这是我的PHP代码:

$places = query( "SELECT * FROM places WHERE MATCH (postal_code, country_code, admin_name1, admin_code1, place_name) AGAINST (?) OR LIKE '%".$_GET["geo"]."%'", $_GET["geo"]);

The error message shows me: 错误消息告诉我:

Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%akutan%''

用这个

$mysql = "SELECT * FROM table WHERE input LIKE '%".mysql_real_escape_string($_GET['name'])."%' ";

It is not good idea to use global variable directly in your mysql query. 直接在mysql查询中使用全局变量不是一个好主意。

so, you must first assign it to some variable and use it 因此,您必须首先将其分配给某个变量并使用它

Like: 喜欢:

$getName = mysql_real_escape_string($_GET['name']);
$mysql = "SELECT * FROM places WHERE `postal_code` LIKE '%".$getName."%' ";

I hope it will help you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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