我在 url 中发送参数。但是当尝试在 url 中写入“0+880”变量时,查询失败。这就是问题所在,这是我的一些代码
$table = $_GET['table'];
$yerId= $_GET['km'];
$sql = pg_query("SELECT turu, hat_kesimi, ili, ilcesi, mahadi FROM $table WHERE km = $yerId");
if (!$sql) {
echo "Problem with query " . $sql . "<br/>";
echo pg_last_error();
exit();
}
这里是 url 和 google 返回的 url:
/weekend/index.php?dbname=tcdd&table=hemzemin_gecit&km=0^880#tab-1
谷歌 react :
查询有问题
ERROR: operator does not exist: character varying = double precision
LINE 1: ...mi, ili, ilcesi, mahadi FROM hemzemin_gecit WHERE km = 0^880
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
另一个网址:
/weekend/index.php?dbname=tcdd&table=hemzemin_gecit&km=0%2B880#tab-1
谷歌 react :
查询有问题
ERROR: operator does not exist: character varying = integer
LINE 1: ...mi, ili, ilcesi, mahadi FROM hemzemin_gecit WHERE km = 0+880
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
最佳答案
这有很多的问题。让我们从:
您没有使用 PDO,您使用的是遗留
pg_
函数;您正在使用带有字符串插值的
pg_query
。 Bobby says hi .参见 SQL injection (wikipedia) , SQL injection (PHP) ;您没有将
$yerId
作为文字引用,例如'$yerId'
,即使不安全 ,您也必须这样做才能使此查询正常工作
请:use PDO , 或 at least pg_query_params
.
关于php - 在 php 中发送加号获取 url 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25907952/