code problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

code problem

Post by irealms »

at the moment approve will approve all and deny will deny all

code is:

Code: Select all

<?php
//show members

$query = "SELECT username,charname,approved,rank,admin FROM users";
$result = mysql_query($query, $db_conn) or die('query failed');
$num_results = mysql_num_rows($result);
echo '<table cellspacing="5" cellpadding="5"><tr><td><div class="log"><u>Username</u></div></td><td><div class="log"><u>Main character name</u></div></td><td><div class="log"><u>Rank?</u></div></td><td><div class="log"><u>Approved?</u></div></td><td><div class="log"><u>Admin?</u></div></td><td><div class="log"><u>User Options</u></div></td></tr>';
while ($row = mysql_fetch_assoc($result)) 
{
	
	if ($row['approved'] == 1)
	{
		$approved = Yes;
	}
    else 
	{
		$approved = No;
	}
	if ($row['rank'] == 1)
	{
		$rank = Officer;
	}
	if ($row['rank'] == 2)
	{
		$rank = Leader;
	}
	elseif ($row['rank'] == 0)
	{
		$rank = Member;
	}
	if ($row['admin'] == 1)
	{
		$adminlvl = Yes;
	}
	else
	{
		$adminlvl = No;
	}
	echo '<tr><td><div class="log">'.$row[username].'</div></td>';
	echo '<td><div class="log">'.$row[charname].'</div></td>';
	echo '<td><div class="log">'.$rank.'</div></td>';
	echo '<td><div class="log">'.$approved.'</div></td>';
	echo '<td><div class="log">'.$adminlvl.'</div></td>'; 
	if ($approved == No)
	{
	echo '<td><div class="log"><a href="index.php?page=members&&useradmin=approve">Approve</a></div></td>';
	if ($useradmin == approve)
		{
		$useradmin = $_GET['useradmin'];
		$query = "UPDATE users set approved = '1' where username = '$row[username]'";
$result2 = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
		if (isset($result2))
			{
			header("Location: index.php?page=members");
			}
		}
	}
	if ($approved == Yes)
	{
	echo '<td><div class="log"><a href="index.php?page=members&&useradmin=deny">Deny</a></div></td>';
	if ($useradmin == deny)
		{
		$useradmin = $_GET['useradmin'];
		$query = "UPDATE users set approved = '0' where username = '$row[username]'";
$result3 = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
		if (isset($result3))
			{
			header("Location: index.php?page=members");
			}
		}
	}
	echo '</tr>';
}
echo '</table>';


?>
i need it to only approve the user for the row where the link is clicked. I inserted it into the while loop as it shows the links for each user.
Last edited by irealms on Wed May 21, 2003 8:01 am, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you change the [syntax=php][/syntax] tags in the post above to [syntax=php][/syntax] tags so that it's a bit easier to read.

Mac
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

done

Post by irealms »

Ok done that, tried a few things and still have the same problem :cry:
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

(

Post by irealms »

:cry:

runnning out of ideas now and can't go further till i sort this
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I'm not sure if I figured it out. I made some changes to the script as follows. Changed lines are commented as so.

Code: Select all

<?php
//show members

$query = "SELECT username,charname,approved,rank,admin FROM users";
//... ...
   if ($approved == No)
   {
   echo '<td><div class="log"><a href="index.php?page=members&useradmin=approve&aproveuser='.$row[username].'">Approve</a></div></td>';  // changed
   if ($useradmin == approve && $row[username] == $approveuser) // changed
      {
      $useradmin = $_GET['useradmin'];
      $query = "UPDATE users set approved = '1' where username = '$approveuser'"; // changed
      $result2 = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
      if (isset($result2))
         {
         header("Location: index.php?page=members");
         }
      }
   }
   if ($approved == Yes)
   {
   echo '<td><div class="log"><a href="index.php?page=members&useradmin=deny&denyuser='.$row[username].'">Deny</a></div></td>'; // changed
   if ($useradmin == deny && $row[username] == $denyuser) // changed
      {
      $useradmin = $_GET['useradmin'];
      $query = "UPDATE users set approved = '0' where username = '$denyuser'"; // changed
      $result3 = mysql_query($query, $db_conn) or die("query [$query] failed: ".mysql_error());
      if (isset($result3))
         {
         header("Location: index.php?page=members");
         }
      }
   }
   echo '</tr>';
   next($array);
}
echo '</table>';?>
Give it a try. I hope it helps.

Cheers,
Scorphus.

ps.: maybe that header function won't work because of this.
Post Reply