4

如果我执行我的 PHP 代码:

$serName = $_GET['username'];
// Code for sanitation here
// [...]
$sql = "SELECT NAME FROM PLAYERS WHERE NAME LIKE '%$serName%'"; 

我得到除法错误,如何在两边都带有通配符的查询中使用变量?

4

2 回答 2

3

正确查询

SELECT NAME FROM PLAYERS WHERE NAME LIKE '%{$serName}%'

你应该使用准备好的语句

于 2013-04-07T16:11:06.333 回答
0
$sql = "SELECT NAME FROM PLAYERS WHERE NAME LIKE '%" .$serName. "%'"; 
于 2013-04-07T16:15:16.807 回答