Monk3h Posted April 11, 2008 Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/ Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 6 People have viewed and no reply.. =/ If you cant see a problem with my script please let me know.. I cant see any errors apart from missing ' inside [] but it will work without em. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-514926 Share on other sites More sharing options...
Zhadus Posted April 11, 2008 Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-514931 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 I just said that wont help.. :/ Iv already been thru it all adding the single qoutes where needed.. Still dosnt work. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-514943 Share on other sites More sharing options...
Zhadus Posted April 11, 2008 Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-514964 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 Like i said before twice.. iv tried every combination of adding ' thats not it. i even tried again and it still wont work. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515022 Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515031 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/monk3h/public_html/chatmsgs.php on line 12 Line 12: $astat = mysql_fetch_assoc($result); Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515032 Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515043 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 Query:select * from players where user='' and pass='' Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515048 Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 There you go then. $user and $pass are undefined. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515051 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 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 https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515056 Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 Presumably you either define $user and $pass on the other pages, or include a file which does? Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515057 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 Its done thrue a session_start in the header Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515078 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 But i cant include the header in the Chat script.. How would i get it to work without including the header? :/ Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515080 Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 Why can't you include it? If there's a reason, you'll need to copy the relevant part from the included file so that $user and $pass are defined. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515097 Share on other sites More sharing options...
Monk3h Posted April 11, 2008 Author Share Posted April 11, 2008 I cant include it because the layout of my site is in the Header/head Footer/foot (.php) and the Chat is in a smaller window. Link to comment https://forums.phpfreaks.com/topic/100670-php-chat-script-help/#findComment-515155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.