Jump to content

Archived

This topic is now archived and is closed to further replies.

dark dude

IF Statement Gone Wrong

Recommended Posts

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

Share this post


Link to post
Share on other sites
try
try
$BannedBy != $Username &&...

(Without the single quotes round Username)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
The "!=" operator means "not equal".

Ken

Share this post


Link to post
Share on other sites
[quote author=onlyican link=topic=102862.msg408856#msg408856 date=1154611890]
try
try
$BannedBy != $Username &&...

(Without the single quotes round Username)
[/quote]

That solved it =]


Thanks a lot =D

Share this post


Link to post
Share on other sites
Dont quote me on this
in PHP
vars 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 show
jamie
$myname

This is handy for some scripts

Share this post


Link to post
Share on other sites

×

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.