Jump to content


Photo

IF Statement Gone Wrong


  • Please log in to reply
6 replies to this topic

#1 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 03 August 2006 - 01:26 PM

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:
$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";
}
}

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

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 01:31 PM

try
try
$BannedBy != $Username &&...

(Without the single quotes round Username)
Tell me the problem, I will try tell you the solution

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 03 August 2006 - 01:50 PM

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?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 August 2006 - 01:56 PM

The "!=" operator means "not equal".

Ken

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 03 August 2006 - 02:01 PM

Ah, thanks Ken.

#6 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 03 August 2006 - 02:35 PM

try
try
$BannedBy != $Username &&...

(Without the single quotes round Username)


That solved it =]


Thanks a lot =D

#7 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 02:38 PM

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

Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users