如果标题中的措辞不正确,我们深表歉意(PHP 新手)。我正在尝试使用下面的 php 脚本从 mysql 数据库返回结果。
php脚本
<?php
require "conn.php";
$adopt_id = $_GET["adopt_id"];
$query = "
select *
from temp_table
where adopt_id = $adopt_id
";
....
?>
现在,如果我在浏览器中按照下面的 url 运行上面的内容,它将按预期返回 http://localhost/searchfeed.php?adopt_id=1
转储上述查询:
select *
from temp_table
where adopt_id = 1
相同的 php 脚本,但对 varchar 数据类型的 diff 字段进行过滤。
php脚本
<?php
require "conn.php";
$GENDER = $_GET["gender"];
$query = "
select *
from temp_table
where gender = $GENDER
";
....
?>
现在,如果我在浏览器中按照下面的 url 运行上面的内容,它会返回 null,因为它没有得到任何结果 = http://localhost/searchfeed.php?gender=M
我将上面的查询转储到日志文件中,看起来它对 $GENDER 没有做任何事情。这就是查询的样子
select *
from temp_table
where gender =
最佳答案
关于使用 varchar 数据类型作为输入的 PHP GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48622255/