Well, I am running a for statement that show numbers up to the rank of the user viewing it. Here is the code:
PHP Code:
<?php
$id = $_GET['id'];
$level = $_SESSION['level'];
// Get User Data
$get = mysql_query("SELECT * FROM `members` WHERE id = '$id' LIMIT 1") or die ("Error Getting User Data! \n<br />\n" .mysql_error());
$u = mysql_fetch_array($get);
$chk = mysql_num_rows($get);
//
// Check Levels
if ($level <= $u['level']) { echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="error">You do not have permission to edit this user</div>'); }
else {
//
########## If Form Sent ##########
if ($_POST['edit']) {
$username = mysql_real_escape_string($_POST['username']);
$map = mysql_real_escape_string($_POST['map']);
$level = mysql_real_escape_string($_POST['level']);
// Format Username
if ( !eregi('[IG]', $username) ) { $username = $username.'[IG]'; }
if ( ereg('[ig]', $username) ) { $username = str_replace('[ig]', '[IG]', $username); }
//
// Insert Data
$insert = mysql_query("UPDATE `members` SET username = '$username', map = '$map', level = '$level' WHERE id = '$id'") or die ("Error Updating User Data! \n<br />\n" .mysql_error());
echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">The user '.$username.' has been edited.</div>');
//
}
########## If Form Not Sent ##########
if (!$_POST['edit']) {
// Check Results
if ($chk < 1) { echo('<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="error">Invalid User ID!</div>'); } else { ?>
<form method="post" action="">
<table width="400" align="center">
<tr>
<td>Username:</td>
<td><input type="text" name="username" value="<?php echo $u['username'] ?>" /></td>
</tr>
<tr>
<td>Test Map:</td>
<td><input type="text" name="map" value="<?php echo $u['map'] ?>" /></td>
</tr>
<?php if ($level >= 8) { ?>
<tr>
<td>Rank Level:</td>
<td>
<select name="rank">
<?php for ($r=1; $r < $level; $r++) { while ($r == $u['level']) { $s = 'selected="selected"'; } ?>
<option <?php echo $s ?>><?php echo $r ?></option>
<? } ?>
</select>
</td>
</tr>
<? } ?>
<tr>
<td></td>
<td><input type="submit" name="edit" value="Edit" /></td>
</tr>
</table>
</form>
<? }
}
}
?>
The numbers are the ranks that the viewing user is allowed to promote another member to. The problem is that I need the member's (the one getting promoted/demoted) rank to be initially selected. Instead of just adding the 'selected="selected"' to the members rank, it adds it to every number after it finds the members rank because $s is now set. How can I make this work? Thanks in advance.
Bookmarks