Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use function return value in write context

Tags:

php

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

like image 956
Msquared86 Avatar asked Mar 16 '11 05:03

Msquared86


1 Answers

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.

like image 55
JohnP Avatar answered Nov 15 '22 09:11

JohnP