在写上下文中不能使用函数返回值 [英] Can't use function return value in write context
问题描述
好的,这是我的代码.应该执行的操作是检索将您引到页面的引荐来源网址,用户将键入someurl.com/refcreate.php?ref=username
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
<?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.
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');
}
?>
好的,我找出了问题所在(或者说是问题所在). 1是否需要看起来像这样的if(refcheck($referer) == false){}
而不是if(refcheck($referer) = false);
.因此,这是一个缺失的等号和错位的冒号:P谢谢
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
推荐答案
您正在分配变量而不是对其进行比较
You're assigning a variable and not comparing it
此refcheck($referer) = false
应该是refcheck($referer) == false
此外,如果您的IF条件失败,则您的方法应该具有默认返回值.
Also, your method should have a default return if your IF condition fails.
这篇关于在写上下文中不能使用函数返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!