我在测试数据库中是否存在字符串时遇到问题!
这是我到目前为止所得到的:
$db = mysqli_connect("localhost", "database", "secret", "user");
if(!$db)
{
exit("Error: ".mysqli_connect_error());
}
$search = 'SELECT * FROM table WHERE ip = $client_ip';
$result = mysqli_query($db, $search);
while($row = mysqli_fetch_object($result)) {
if (isset($row->blocked)) {
echo 'You are blocked!';
} else {
echo 'You are not blocked!';
}
但这对我来说不起作用。 $ client_ip之前已正确定义。
答案 0 :(得分:3)
您需要将$client_ip
括在引号中,因为它是一个字符串:
$search = "SELECT * FROM table WHERE ip = '$client_ip'";
答案 1 :(得分:0)
试试这个:
$search = "SELECT * FROM table WHERE ip = '{$client_ip}'";