-5

Error - Cannot use isset() on the result of an expression (you can use "null !== expression" instead)

I'm getting the error above the start of the if statement and the else line.

Iv done the code the way I have because , the $user_id is chosen from a drop down box, Unless its the first option from that box which doesn't have a value.

The code below should be able to tell if the option from the dropdown box has a value . If so it displays just information relevant to that user. Otherwise it will show everything.

 $user_id = $_REQUEST['userid'];
    $user_hack = 0;

    echo $user_hack;

    if(isset($user_id > $user_hack)) 
    {
        echo "Yup";

         $sql = "SELECT ub.id, users.name, individualbadges.badgename, ub.level FROM userbadges ub INNER JOIN users ON users.id = ub.user_id INNER JOIN individualbadges ON individualbadges.id = ub.badge_id WHERE users.id = $user_id ";
    }
    else 
    {
        die("Parameter is missing!"); 

        $sql = 'SELECT ub.id, users.name, individualbadges.badgename, ub.level FROM userbadges ub INNER JOIN users ON users.id = ub.user_id INNER JOIN individualbadges ON individualbadges.id = ub.badge_id';
    }
    $query = mysqli_query($connection, $sql);
Jess
  • 133
  • 3
  • 12
  • 2
    The error is telling you exactly what's wrong. `isset()` is used on variables, not expressions. – David Jun 22 '15 at 12:48
  • `isset() only works with variables as passing anything else will result in a parse error` http://php.net/manual/en/function.isset.php – Abhik Chakraborty Jun 22 '15 at 12:50

1 Answers1

1

Just change the condition to:

if(isset($_REQUEST['userid']) && $_REQUEST['userid'] > $user_hack) 

isset tells is a variable is set, while this statement may be true or false, on which you cannot call isset function.

Until you check if(isset($_REQUEST['userid'])), you cannot assign it to $userid variable.

n-dru
  • 9,285
  • 2
  • 29
  • 42
  • can you help with this - Notice: Undefined index: userid in . I get this when the page first loads . – Jess Jun 22 '15 at 12:51
  • because you don't check if it is set first. Just move `$user_id = $_REQUEST['userid'];` assignment after `if` condition, then it is sure that it is set. – n-dru Jun 22 '15 at 12:53