Php I';我将用户输入与MySQL数据库进行比较,但我';我得到了错误的结果
我正在写一个代码来比较用户输入和数据库。当用户输入数据库中已经存在的单词时,我希望代码显示“is phishing”Php I';我将用户输入与MySQL数据库进行比较,但我';我得到了错误的结果,php,Php,我正在写一个代码来比较用户输入和数据库。当用户输入数据库中已经存在的单词时,我希望代码显示“is phishing” <?php include 'backend.php'; $userinput = $_POST['userinput']; if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($
<?php
include 'backend.php';
$userinput = $_POST['userinput'];
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
if($userinput==isset($row['keywords']))
{
echo "is phishing";
}else{
echo "is legitimate";
}
}
?>
函数返回一个布尔值,指示您提供的参数是否已设置。i、 e.参数不是null
或已声明且从未初始化
如前所述,要在数组中搜索值,需要使用in_array()
函数。因此,您的代码应该是:
if(in_array($userinput, $row['keywords']))
{
echo "is phishing";
}else{
echo "is legitimate";
}
请注意,数组()中的区分大小写。在这种情况下:
$values = ["StackOverflow"];
in_array("StackOverflow", $values); //true
in_array("stackoverflow", $values); //false
不要使用isset函数,它返回true/false,您正在将一个变量与布尔值进行比较,如果该数据来自表示已设置的数据,只需删除isset函数即可