所以我有桌子:
这是代码:`
mysqli_query($con,"INSERT INTO ip_check (ip_check_address, ip_check_id) VALUES ($encode , $id)");
$ip = $_SERVER['REMOTE_ADDR'];
$encode = ip2long($ip);
$id = htmlspecialchars($_GET["keywordid"]);
$check_id = mysqli_query($con,"SELECT ip_check_id FROM ip_check
WHERE ip_check_address = $encode");
if ($check_id != $id ) {..}
`
我需要检查是否已经使用了ip_check_id。
答案 0 :(得分:1)
mysqli_query($con,"INSERT INTO ip_check (ip_check_address, ip_check_id)
VALUES ($encode , $id)");
$ip = $_SERVER['REMOTE_ADDR'];
$encode = ip2long($ip);
$id = htmlspecialchars($_GET["keywordid"]);
$check_id = mysqli_query($con,"SELECT ip_check_id FROM ip_check
WHERE ip_check_address = $encode");
$query = @mysqli_query($check_id);
while($row = @mysqli_fetch_array())
{
$check_id = $row['ip_check_id'];
if ($check_id== $id )
{
//here it is equal, returns ture
}
else
{
// here returns false
}
}
答案 1 :(得分:1)
修改强>
$check_id = mysqli_query($con,"SELECT ip_check_id FROM ip_check
WHERE ip_check_address = $encode");
while($row = mysqli_fetch_array($check_id))
{
$check_if_exist = $row['ip_check_id'];
if ($check_if_exist != $id )
{
// it does not equal
}
}
Origninal回答,我误解了这个问题。
“我需要检查是否已经使用了ip_check_id。”
<强> 旁注: 强>
您现有的代码向SQL injection开放 使用prepared statements或PDO with prepared statements。