Parse error: syntax error, unexpected T_VARIABLE, waiting for T_FUNCTION

Can someone tell me what I am doing wrong?

I want to show users online only in certain rooms.

the code below is a function that calls my online .php, it is under my chat.php, when I load the page, this function also loads.

function whos_online() {
  if ( window.XMLHttpRequest ) {
    xmlhttp = new XMLHttpRequest();
  } else { 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET", "online.php?room=<?php $_SESSION['room']?>", false);
  xmlhttp.send();
  document.getElementById("whos_online").innerHTML = xmlhttp.responseText; 
}

online.php

this is the content of my online.php

<link rel="stylesheet" type="text/css" href="style.css" />
<?php

    session_start();
    include 'db.inc.php';

    class WhosOnline{
        $rn = $_GET['room'];
        protected $get_status_query = "SELECT * FROM `online_users` WHERE `room` = '{$rn}'";
        public function DisplayUsers(){
            $get_current_status = mysql_query( $this->get_status_query );
            if( mysql_num_rows( $get_current_status ) != 0 ) {
                while( $row_status = mysql_fetch_array( $get_current_status ) ) {
                    if( $_SESSION['username'] == true ) {
                        echo "<div class='online_margin'>
                                <b>".base64_decode($row_status['username'])."</b>
                              </div>
                              <hr style='border: 0; border-top: solid 1px #D8D8D8;margin: 5px 10px 5px 10px;' />";
                    }
                }
            }
        }
    }

    $Online = new WhosOnline;
    $Online->DisplayUsers();
?>

Any help?

+2
source share
3 answers

Ok, even this gives an error:

class WhosOnline{
    public $rn = $_GET['room'];
}

This also gives an error:

$v = "Hi there";
class WhosOnline{
    public $rn = $v;
}

, . . CONSTANTS ( ). WhosOnline :

public function DisplayUsers(){
    $get_current_status = mysql_query(
        "SELECT * FROM `online_users` WHERE `room` = '" 
            . mysql_real_escape_string($_GET['room']) . "'");
    if(mysql_num_rows($get_current_status)!=0){
        while($row_status = mysql_fetch_array($get_current_status)){
            if($_SESSION['username']==true){
                echo "<div class='online_margin'>   <b>".base64_decode($row_status['username'])."</b></div><hr style='border: 0; border-top:  solid 1px #D8D8D8;margin: 5px 10px 5px 10px;' />";
            }
        }
    }
}

, $this->.

+1
$rn = $_GET['room'];
protected $get_status_query = "SELECT * FROM `online_users` WHERE `room` =     '{$rn}'";

, RIGHT NOW.

protected function get_status_query($rn) {
  return "SELECT * FROM `online_users` WHERE `room` =     '". sanitize($rn) . "'";
};

sanitize() .

+2

you cannot initialize any variable directly in the class, try this

public $rn;
protected $get_status_query;

public __construct(){
      $this->rn = $_GET['room'];
      $this->get_status_query = "SELECT * FROM `online_users` WHERE `room` = '{$this->rn}'";
}
+2
source

All Articles