-1

Having an issue with my code, it's strange because the exact same code works in another .php file but not in this one for whatever reason. I get the error:

Notice: Use of undefined constant logged - assumed 'logged' in ... on line 54

The code below is where the error is said to be. At the IF statement. The second piece of code in tags is the function. It's stored in a separate file 'functions.php'.

<?php
    include 'functions.php';
    $logged = @logged_in($_SESSION['uuid']);
      
    if(logged==true){
        echo 'logged in';
    }
?>

<?php

function logged_in($uuid){
    $servername="localhost";          
    $dbusername="root";                 
    $dbpassword="usbw";                    
    $database="randomfacts";           
    $link=mysql_connect($servername,$dbusername,$dbpassword);
    if(! $link){
        die('Connection Failed'.mysql_error());
    }
    mysql_select_db($database,$link);
      
    $query = "SELECT * FROM users WHERE uuid='$uuid'";
    $rows = mysql_query($query) or die(mysql_error());
    $count = mysql_num_rows($rows);
      
    if($count==0){ 
        return false;
    }else{
        return true;
    }
  
    mysql_close($link);  
}

?>
Axel
  • 3,331
  • 11
  • 35
  • 58
Luke Holland
  • 142
  • 1
  • 9

2 Answers2

1

change

if(logged==true)

to

if($logged==true)
Axel
  • 3,331
  • 11
  • 35
  • 58
1

$logged is a variable. You're missing the dollar sign ($) in the expression that issues the warning, so PHP parses logged as the name of a constant, but, of course, no constant is defined with that name.

mr_carrera
  • 76
  • 6