php 不能在写上下文中使用函数返回值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5321522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't use function return value in write context
提问by Msquared86
Ok, here is my code. What it is supposed to do is retrieve the referer that sent you to the page, the user will type someurl.com/refcreate.php?ref=username
好的,这是我的代码。它应该做的是检索将您发送到页面的引用者,用户将输入 someurl.com/refcreate.php?ref=username
<?php
session_start();
$referer = $_GET['ref'];
$_SESSION['referer'] = $referer;
if (!isset($referer))
{
echo 'You did not specify a referer, please correct this to continue';
die;
}
elseif($referer == "")
{
echo 'You did not specify a referer, please correct this to continue';
die;
}
The above part works fine if they forgot to specify the referer. The below half is to check if the current referer specified is an actual user in the database.
如果他们忘记指定引用者,上述部分工作正常。下半部分是检查当前指定的referer是否是数据库中的实际用户。
if(refcheck($referer) = false)
{
echo 'that referer is not in our database,please double chek the spelling and try again.';
die;
}
function refcheck($ref)
{
require('mysql_con.php');
$query="SELECT username FROM jos_users WHERE username='". $ref ."'";
echo $query;
$result = mysql_query($query, $con);
$exists =mysql_fetch_assoc($result);
if ($exists != false)
{
//return true;
echo 'true';
return true;
}
require('mysql_close.php');
}
?>
OK, I figured out the problem (or problems rather). 1 was it needed to look like this if(refcheck($referer) == false){}
instead of if(refcheck($referer) = false);
. So it was a missing equal sign and a misplaced colon :P thanks guys
好的,我想出了问题(或者更确切地说是问题)。1 是否需要看起来像这样if(refcheck($referer) == false){}
而不是if(refcheck($referer) = false);
. 所以这是一个缺少的等号和一个错位的冒号:P谢谢大家
回答by JohnP
You're assigning a variable and not comparing it
您正在分配一个变量而不是比较它
This refcheck($referer) = false
这个 refcheck($referer) = false
Should be refcheck($referer) == false
应该 refcheck($referer) == false
Also, your method should have a default return if your IF condition fails.
此外,如果您的 IF 条件失败,您的方法应该有一个默认返回值。
回答by Msquared86
ok i figured out hte problem or problems rather 1 was it need to look like this if(refcheck($referer) == false){} instead of if(refcheck($referer) = false); so a missing equal sign and a misplaced colon :P thanks guys
好的,我发现了问题或问题 1 是否需要看起来像这样 if(refcheck($referer) == false){} 而不是 if(refcheck($referer) = false); 所以缺少等号和错位的冒号 :P 谢谢大家
回答by nv39
you misspelled "check" in the third line
你在第三行拼错了“check”