Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

php - Can't use function return value in write context

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');
    }
    ?>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're assigning a variable and not comparing it

This refcheck($referer) = false

Should be refcheck($referer) == false

Also, your method should have a default return if your IF condition fails.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...