Jump to content

[SOLVED] Use of undefined constant


cheechm

Recommended Posts

Hello,

Whenever I run this I get:

Notice: Use of undefined constant online - assumed 'online'

function update_sessions()
{
        $sid = session_id();
        if($_SESSION[online] == "1")
        {
                mysql_query("UPDATE `sessions` SET `time` = '". time() ."' WHERE `sid` = '$sid'") or die(mysql_error());
        }
        else
        {
                $_SESSION[online] = 1;
                mysql_query("INSERT INTO `sessions` SET `time` = '". time() ."', `sid` = '$sid'") or die(mysql_error());
        }
}

function get_onlineusers()
{
        $min = time() - 301;
        mysql_query("DELETE FROM `sessions` WHERE `time` <= '$min'") or die(mysql_error());
        $query = mysql_query("SELECT COUNT(sid) FROM `sessions`");
        $num = mysql_fetch_row($query);
        return($num[0]);
}

 

What is the problem?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/76900-solved-use-of-undefined-constant/
Share on other sites

Array keys which are not integers should be enclosed in single quotes, e.g.:

 

$_SESSION['online']

 

You'll see them not done like this a lot of the time, since you only recieve a notice for this kind of minor error, and a lot of people have PHP set up not to report notices.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.