2

I am working on a ' Show Online user' script where the script show everybody who is online. Now i want to remve the entry which matches the session user name i.e "if (Online user = Session User name ) then do not display it , just like on facebook.com chat where your friends id is shown and not your own Id my code is as follows :

    <?php
    mysql_connect("localhost","root","12345");
    mysql_select_db("accounts");
    $user = $_SESSION['user_name'];
    $result = mysql_query("SELECT * FROM online * WHERE ($chat<>$user)");

    while($row=mysql_fetch_array($result)) {
      $chat=$row["emp_name"];
      $chlk = ("<a href=javascript:void(0) onclick=javascript:chatWith('$chat')>$chat</a>");
      $chs = ("<a>$chat</a>");
      if ($chat <> $user) {
      echo $chlk;
      }
      else {
      echo $chs;
      }
   echo $chlk;
}
?>

I am getting the following error :

Notice: Undefined variable: chat in localhost/accounts/removeuser.php on line 7

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given localhost/accounts/removeuser.php on line 9

Any help is highly appreciated.

2
  • make sure $result does not have boolean....share code for $result Commented Mar 23, 2013 at 11:46
  • 1
    I think your problem is in "removeuser.php" line 9... Commented Mar 23, 2013 at 11:47

2 Answers 2

2

Correction in query.

"SELECT * FROM online WHERE ($chat<>$user)"

OR

Replace $chat in query with your table field name.

there is extra * before WHERE that is invalid.

and $chat is not defined in query.

Sign up to request clarification or add additional context in comments.

4 Comments

i tried the correction but the script still gives the same error , could you recommend a script where all users are show except the user which is viewing the list ?
"SELECT * FROM online WHERE username != '".$_SESSION['loggedInUser']."'"
thanx i got it , but not the way you told , i used not like .. ` SELECT * FROM online WHERE emp_name NOT LIKE '%$user%'"`
@AadityaChakravarty well even emp_name != '$user'" also work..because if you have aaditya and aadit in table then both not selected so use != is best to eliminate exact user.
0

<> is not PHP as far as I know. You need to use !==.

(and probably read up on some PHP basics...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.