我有一个带数字的mysql数据库,例如:0655456246或0641698646 ...... 我将使用以下脚本在我的数据库中搜索这些结果:
if ($Recipient != $checknumber)
{
...
}
else
{
echo '<SCRIPT LANGUAGE="JavaScript">alert("ERROR")</script>';
}
我现在想逐一比较结果,看看它是否与用户在表单字段中输入的内容相对应,但问题是在示例的2个数字上,该比较与0641698646有效但不与0655456246.我不明白为什么......我只是想要,如果用户将数字中已有的数字之一放入数据库中,则必须拒绝访问他。
$ Recipient =&gt;是用户在表单
中输入的数字[{"id":"18","time_start":"2008-01-01 19:00:00+03","time_end":"2008-01-01 19:01:00+03","task":"test","task_type":"","date":"2017-07-03 00:00:00+03","task_result":"asdasd","username":"test_rakov","time_duration":"00:01:00"},{"id":"20","time_start":"2008-01-01 19:00:00+03","time_end":"2008-01-01 20:00:00+03","task":"asdasdasdasdsdf asdas","task_type":"","date":"2017-07-03 00:00:00+03","task_result":"asdasd","username":"test_rakov","time_duration":"01:00:00"},{"id":"21","time_start":"2008-01-01 12:00:00+03","time_end":"2008-01-01 14:00:00+03","task":"asdasdasdasdasd","task_type":"","date":"2017-07-03 00:00:00+03","task_result":"asdasd","username":"test_rakov","time_duration":"02:00:00"},{"id":"19","time_start":"2008-01-01 18:21:51+03","time_end":"2008-01-01 18:22:00+03","task":"asdasd","task_type":"","date":"2017-07-02 00:00:00+03","task_result":"","username":"test_rakov","time_duration":"00:00:09"}]
感谢您的帮助:)
答案 0 :(得分:1)
从您发布的代码看起来,您在mysqli_fetch_assoc循环后进行检查,这意味着$ checknumber只会从数据库中检索最后一个值。尝试这样的事情:
$found=false;
$result6=mysqli_query($conn2, "SELECT number FROM sms_stop");
while ($check2=mysqli_fetch_assoc($result6))
{
$checknumber = implode(str_replace("+33", "0", $check2));
if ($checknumber==$Recipient)
$found=true;
}
if ($found==false)
{
...
}
else
echo '<SCRIPT LANGUAGE="JavaScript">alert("ERROR")</script>';