Chat Box not displaying usernames

Hi, originally I coded this chatbox with Ajax but it kept spazzing (refreshing blinkingly on occasion) so I switched it to iframes. Everything works fine when logged in, all the usernames show. However when logged out all usernames are blank (except for the ‘guest’ users).

chat.php
[php]<?php
include(‘config.php’);

if(isset($_POST[‘form’]))
{
$message = mysql_real_escape_string($_POST[‘message’]);
$time = time();
if($_SESSION[‘id’] != “”) { $userID = $_SESSION[‘id’]; }
else { $userID = 0; }
mysql_query(“INSERT INTO chat (userID, time, message) VALUES (’$userID’, ‘$time’, ‘$message’)”) or die(mysql_error());
}

echo ’

Message:
';

?>[/php]

chat_hist.php
[php]<?php

include(‘config.php’);

$query = mysql_query(“SELECT * FROM chat ORDER BY id DESC LIMIT 20”);
while($row = mysql_fetch_assoc($query))
{
if($row[‘userID’] == 0) { $player = ‘Guest’; }
else
{
$player_q = mysql_query(“SELECT * FROM users WHERE id=’” . $_SESSION[‘id’] . “’”);
$player_r = mysql_fetch_assoc($player_q);
$player = $player_r[‘callname’];
}
echo ‘

’ . $player . ': ’ . $row[‘message’] . ’

’ . date(‘m-d h:i:s’, $row[‘time’]) . ‘
’;
}

?>[/php]

Any idea why the players names aren’t showing up when logged out?

Are you closing the session when they log out? If so, you have session code in the parts you showed us.
Perhaps you are dropping your session and it is not getting back to the database to show the users.

Just a thought. How are you “logging-out”?

Sponsor our Newsletter | Privacy Policy | Terms of Service