English 中文(简体)
差错:先天错误 T_ARIABLE, 期望T_UNNCTION
原标题:Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

难道有人会告诉我我我我我我什么是错的?

我只想在具体会议室在线展示用户。

the code below is the function that calls my online.php this 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

这是我在线的内容。 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();
?>

任何帮助?

最佳回答

Ok甚至造成错误:

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

这还造成错误:

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

之所以出现错误,是因为你试图根据类别定义中另一个变量确定一个变量。 你可以在建筑商中这样做。 或者,你可以根据《公约》确定阶级成员(如你在座标)。 但是,为什么不像这样改写你的人:

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->缺失。

问题回答
$rn = $_GET[ room ];
protected $get_status_query = "SELECT * FROM `online_users` WHERE `room` =      {$rn} ";

这是一种坏的习惯,你需要打破Rright NOW

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

《<代码>sanitize()》的实施留给读者。

您不能直接在班级中选择任何变量,试图这样做。

public $rn;
protected $get_status_query;

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




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签