[英]If else not working properly
So I made page with unban request and in users table I save if user already sent request or not so I don't have multiple unban requests from one user.Now when I check if user sent request it's not working.In database it stands 0 and it's still showing me error pop out.因此,我创建了带有取消禁止请求的页面,并在用户表中保存了用户是否已发送请求,因此我没有来自一个用户的多个取消禁止请求。现在,当我检查用户是否发送请求时,它不起作用。在数据库中,它为 0它仍然向我显示错误弹出。 Here is code, thanks for help in advance这是代码,提前感谢您的帮助
if(isset($_POST['btn-unban_req']))
{
if($unban_sent = 0)//THIS IS WHERE I CHECK
{
//MY THIGNS HERE
if($connection ->query($unbanquery) === TRUE)
{
//MY THIGNS HERE
if ($connection->query($sentquery) === TRUE)
{
}
else
{
echo $connection->error;
}
}
else
{
}
}
else // AND I GET THIS ERROR EVEN IF IT STANDS 0 IN DATABASE
{
echo "Unban already sent!";
}
}
In line 3 you missed a =
for comparision.在第 3 行中,您错过了一个=
进行比较。 Instead, you set $unban_set
to 0
相反,您将$unban_set
设置为0
Try it with this code:用这个代码试试:
if(isset($_POST['btn-unban_req']))
{
if($unban_sent == 0) //<- Now you are checking it here
{
//MY THIGNS HERE
if($connection ->query($unbanquery) === TRUE)
{
//MY THIGNS HERE
if ($connection->query($sentquery) === TRUE)
{
}
else
{
echo $connection->error;
}
}
else
{
}
}
else // AND I GET THIS ERROR EVEN IF IT STANDS 0 IN DATABASE
{
echo "Unban already sent!";
}
}
You're using this code which is wrong.您正在使用此代码是错误的。
$unban_sent = 0
$unban_sent = 0
means to assign 0
to $unban_sent
$unban_sent = 0
表示给$unban_sent
赋值0
It should be:它应该是:
$unban_sent == 0
$unban_sent == 0
means $unban_sent
is equal to 0 $unban_sent == 0
表示$unban_sent
等于 0
==
is for comparison , =
is for assignment , and ===
is for identical or same type . ==
用于比较, =
用于赋值,而===
用于相同或相同类型。
More information at http://php.net/manual/en/language.operators.comparison.php .更多信息请访问http://php.net/manual/en/language.operators.comparison.php 。
You are not comparing the values, this is assigning the values:您不是在比较值,而是在分配值:
if($unban_sent = 0) // assigning values
This should be:这应该是:
if($unban_sent == 0) // comparing values
Basic Example:基本示例:
Lets say,可以说,
1 = 1
its assigning 1 = 1
其分配1 == 1
its checking the condition will return TRUE. 1 == 1
检查条件将返回 TRUE。
For more help: PHP Comparison Operators如需更多帮助: PHP 比较运算符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.