Jump to content

PHP Chat Script Help


Monk3h

Recommended Posts

For some reason the Admin section to this code dosnt work and i have no idea why.

 

 

Here is my Script:

 

<META HTTP-EQUIV=Refresh CONTENT="15;url=chatmsgs.php">
<link rel=stylesheet href=style.css>

<?php
mysql_pconnect("(REMOVED FOR SECURITY REASONS)","(REMOVED FOR SECURITY REASONS)","(REMOVED FOR SECURITY REASONS)");
mysql_select_db("(REMOVED FOR SECURITY REASONS)");
$csel = mysql_query("select * from chat order by id desc limit 15");
while ($chat = mysql_fetch_array($csel)) 
{
$astat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
if ($astat[rank] == Admin) {
print "<b>$chat[user]</b>: $chat[chat] TEST<br>";
}else{

print "<b>$chat[user]</b>: $chat[chat]<br>";
}}

$psel = mysql_query("select * from players where page='Chat'");
$ctime = time();
while ($pl = mysql_fetch_array($psel)) {
$span = ($ctime - $pl[lpv]);
if ($span <= 180) {
	if ($pl[rank] == Admin) {
		$on = "$on [!$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])] ";
	} else {
		$on = "$on [$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])] ";	
	}	
	$numon = ($numon + 1);
}
}
print "<font class=normal><center><br><br><br>$on<br>";
$numchat = mysql_num_rows(mysql_query("select * from chat"));
print "There are <b>$numchat</b> chat lines. | <b>$numon</b> players in chat.<br>";
print "[<a href=chatmsgs.php?view=chat&userid=$userid>Chat</a>][<a href=chatmsgs.php?view=whispers&userid=$userid>Whispers</a>][<A href=chatmsgs.php?view=reference&userid=$userid>cML</a>]</font>";

?>

 

 

This is the bit that dosnt work:

 

 

if ($astat[rank] == Admin) {
print "<b>$chat[user]</b>: $chat[chat] TEST<br>";

 

 

The text TEST just wont apear at the end of all lines.. Yes i am admin and yes the script does work apart from this.

 

When i try adding TEST on the end of the other part (if the user isnt an admin) it shows.

 

Im guessing this bit is wrong.

 

$astat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));

 

 

Can anyone help me please?

Link to comment
Share on other sites

Try adding single quotes to the rank bit.

 

if ($astat['rank'] == Admin) {
print "<b>$chat[user]</b>: $chat[chat] TEST<br>";
*AND*
if ($pl['rank'] == Admin) {
		$on = "$on [!$pl[tag]<A href=view.php?view=$pl[id]>$pl[user]</a> ($pl[id])] ";

Link to comment
Share on other sites

Ahh yeah sorry, I definitely missed that part. Was staring at the code for a while.

The problem, it seems, is that you're comparing a string value with a constant.

if ($astat['rank'] == Admin) {
*TO*
if ($astat['rank'] == 'Admin') {

 

That is, if you don't have Admin defined elsewhere and assuming $astat[rank] is a String.

Link to comment
Share on other sites

Debug and print the query and row. Sounds like it isn't selecting the correct row or there's a difference in fields names:

 

<?php
$astat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
//becomes:
$sql = "select * from players where user='$user' and pass='$pass'";
$result = mysql_query($sql) or die(mysql_error());
$astat = mysql_fetch_assoc($result);
echo '<br />Query:'.$sql.'<br />';
echo '<pre>'.print_r($astat,1).'</pre>';
?>

Link to comment
Share on other sites

Sorry, my fault (but i do have a excuse, im ill). Try:

 

<?php
$astat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
//becomes:
$sql = "select * from players where user='$user' and pass='$pass'";
$result = mysql_query($sql) or die(mysql_error());
$astat = mysql_fetch_assoc($result);
echo '<br />Query:'.$sql.'<br />';
echo '<pre>'.print_r($astat,1).'</pre>';
?>

Link to comment
Share on other sites

What do you mean? i use

 

$astat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));

 

 

On every other page and all i have to do is type $stat[feildname] and it brings back what ever i need.. Why wouldnt it work this time? :S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.