dark dude Posted August 3, 2006 Share Posted August 3, 2006 Ok, I have set an If statement on my website so users with the status "Game Moderator" can't unban users banned by another Staff member.This is the script:[code=php:0]$query="SELECT * FROM Users WHERE Username='$Unbantarget'";$result=mysql_query($query);$Status2=mysql_result($result,$i,"Status");$BannedBy=mysql_result($result,$i,"BannedBy");$query="SELECT * FROM Banned WHERE Username='$Unbantarget'";$result=mysql_query($query);$num=mysql_numrows($result);if($BannedBy!='$Username' && $Status=='Game Moderator'){echo "<span style=color:red>".$Username.", You cannot unban a user you did not ban!<br> Contact the Game Moderator (".$BannedBy.") of the User.";} else {if($Status2=='Banned'){$query="UPDATE Users SET Status='User', BannedBy='', BannedOn='', BannedUntil='', BannedFor='' WHERE Username='$Unbanvictim'";mysql_query($query);$query="UPDATE Banned SET BannedFor='$Condition' WHERE Username='$Unbanvictim' && BanTime='$num'";mysql_query($query);echo "User ".$Unbantarget." has been successfully unbanned!";} else {echo "Typo error? Stupidity? Either way, the user isnt banned";}}[/code]However, when I debugged this by trying to unban a user I had banned, it came up with the message "Test, You cannot unban a user you did not ban!Contact the Game Moderator (Test) of the User."What's going on? o.O Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/ Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 trytry$BannedBy != $Username &&...(Without the single quotes round Username) Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68527 Share on other sites More sharing options...
hostfreak Posted August 3, 2006 Share Posted August 3, 2006 I dont get wht there is an exclamation mark?if($BannedBy!='$Username' && $Status=='Game Moderator'){Just out of curiousity and for my own knowledge, can someone tell me? Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68536 Share on other sites More sharing options...
kenrbnsn Posted August 3, 2006 Share Posted August 3, 2006 The "!=" operator means "not equal".Ken Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68542 Share on other sites More sharing options...
hostfreak Posted August 3, 2006 Share Posted August 3, 2006 Ah, thanks Ken. Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68546 Share on other sites More sharing options...
dark dude Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=onlyican link=topic=102862.msg408856#msg408856 date=1154611890]trytry$BannedBy != $Username &&...(Without the single quotes round Username)[/quote]That solved it =] Thanks a lot =D Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68570 Share on other sites More sharing options...
onlyican Posted August 3, 2006 Share Posted August 3, 2006 Dont quote me on thisin PHPvars in double quotes (") come out as vars Vars in Single Quotes are literal and come out at printed $myname = "jamie";echo "$myname<br />";echo '$myname';will showjamie$mynameThis is handy for some scripts Link to comment https://forums.phpfreaks.com/topic/16447-if-statement-gone-wrong/#findComment-68575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.