Page 1 of 1

if commands with $row

Posted: Tue Jan 16, 2007 11:57 am
by ekosoftco
If this isnt supposed to be here im sorry, it has php and database.
I have this code, where it searches to see if the guild = the guild set in the user database. If it does, it checks the rank in the user database for that guild, so if the rank=leader, theyre leader of the guild. Right now i have the character set to recruiter, and it doesnt show up the add member section its supposed to, and im not seeing why. Ive tried not using variables and just putting the raw

Code: Select all

if ($row['Rank'] == Recruiter)
and it hasent worked either. Heres my code to see.

Code: Select all

if($_SESSION['Uname'] == "")
	  	{
	  	echo error();
	  	}
	  	else
	  	{	 
			$result = mysql_query("SELECT * FROM `loginphp` WHERE `Guild` = '{$_SESSION['Guild']}'") or die(mysql_error());
			$row = mysql_fetch_array( $result ); //set $row to result
			$_Rank = str_replace("<", "", $row['Rank']);
			if($row['Guild'] == $_SESSION['Guild'])
			{
			$Leader = "Leader";
			$Admin = "Admin";
			$Recru = "Recruiter";
			echo "<center><font color=000000 span class='style3'><b>Welcome to " . $_SESSION['Guild'] . " " . $_SESSION['Uname'] . "!</b>
<br>Rank: " . $_Rank . "<br></font>";
			echo "<font color=000000 span class='style3'><a href=guildcp.php?action=members>Members</a>&nbsp;&nbsp;&nbsp;&nbsp;";
				if($row['Rank'] == $Leader)
				{
				echo "<font color=000000 span class='style3'><a href=guildcp.php?action=editinfo>Edit Guild Info</a><br>";
				}
					if($row['Rank'] == $Admin || $row['Rank'] == $Leader)
					{
					echo "<font color=000000 span class='style3'><a href=guildcp.php?action=editmember>Edit Members</a>&nbsp;&nbsp;&nbsp;&nbsp;";
					}
						if($row['Rank'] == $Recru)
						{
						echo "<font color=000000 span class='style3'><a href=guildcp.php?action=add>Add Member</a><br>";
						}
			}
			else
			{
			echo member();
			}
	}

function error()
{
echo "<font color=000000 span class='style3'><b>You must login to use this feature!</b>";
}
function member()
{
echo "<font color=000000 span class='style3'><b>You must create a guild first or be a member!</b>";
}

Posted: Tue Jan 16, 2007 2:08 pm
by John Cartwright
Put this right above where you make your compirison for the ranks. Standard debugging..

Code: Select all

echo 'Recruit : '; var_dump($Recru); echo '<br />';
echo 'Rank : '; var_dump($row['Rank']); echo '<br />';
echo 'Comparison : '; var_dump($Recru == $row['Rank']); echo '<br>';

Posted: Tue Jan 16, 2007 6:52 pm
by ekosoftco

Code: Select all

Recruit : string(9) "Recruiter" 
Rank : string(0) "" 
Comparison : bool(false)
i have no idea what those mean :(

Posted: Tue Jan 16, 2007 7:27 pm
by John Cartwright
I forgot to mention to turn on error_reporting(E_ALL); at the top of your script, it will help you see which variables are undefined.
ekosoftco wrote:

Code: Select all

Recruit : string(9) "Recruiter" 
Rank : string(0) "" 
Comparison : bool(false)
i have no idea what those mean :(
It means that $row['Rank'] is empty

Posted: Tue Jan 16, 2007 8:09 pm
by ekosoftco
Thats weird, because ive checked the field too many times, its value is recruiter.
i get this now

Code: Select all

Recruit : string(9) "Recruiter" 
Rank : string(0) "" 
Comparison : bool(false) 


Welcome to SLX Cyril! 
Rank: 
Members    
Notice: Use of undefined constant Leader - assumed 'Leader' in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 191
Edit Guild Info

Notice: Use of undefined constant Admin - assumed 'Admin' in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 195
Edit Members    
Notice: Use of undefined constant Recruiter - assumed 'Recruiter' in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 199
Add Member

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 218

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 237

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 243

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 267

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 271

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 290

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 297

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 302

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 306

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 310

Notice: Undefined index: action in /hosted/subs/ulmb.com/c/y/cyril/public_html/guildcp.php on line 338
now im completely stuck xD

Posted: Tue Jan 16, 2007 11:20 pm
by aaronhall
You must use single quotes to encapsulate array indices (e.g. $_POST['asdf'] and not $_POST[asdf]). Those "undefined constant" notices will magically disappear.

The "undefined index" notices indicate that you are referencing an array key that hasn't been set, presumably in your $row array. Have you checked that your query isn't returning and empty result set (mysql_num_rows())?