echo'On this page you can edit the rank of a user.
<p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Username to Edit:<br>
<input name="Username" type="text" class="textBox"></p>
<p>Change To:<br>
<select>
<option>Banned</option>
<option>Admin</option>
<option>User</option>
</select></p>
<p><input type="submit" value="Change Rank" name="changerank"></p>
</form>
';
}
How would I define what user level Banned, Admin and User are? I am trying to make a Edit User page, but when I go to write the SQL for it, it needs to know what each level is… Can I do it with an if statement?
You will need to name your <select> tag as:
<select name="user_level">...</select>
Once the page is posted, you can see $_POST[‘user_level’] variable.
case'editusr':
include('config.php');
if($_SESSION['s_rank'] == "2") {
echo'You do not have the permissions to view this page.';
}
if($_SESSION['s_rank'] == "1") {
$ranks = array('Banned' => 0, 'User' => 1, 'Admin' => 2);
echo'On this page you can edit the rank of a user.
<p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Username to Edit:<br>
<input name="Username" type="text" class="textBox"></p>
<p>Change To:<br>
<select name="user_level">
<option value="' .$ranks['Banned'].'">Banned</option>
<option value="' .$ranks['Admin'].'">Admin</option>
<option value="' .$ranks['User'].'">User</option>
</select></p>
<p><input type="submit" value="Change Rank" name="changerank"></p>
</form>
';
}
break;
So, that is what it should look like right now, correct?
So, now I can just run the MySQL to Update, right? Or am I missing a step here?
You can define the values elsewhere in your code:
$ranks = array('Admin' => 1, 'Banned' => 2, 'User' => 3);
Then in the html:
echo '<select>
<option value="' . $ranks['Banned'] . '">Banned</option>
<option value="' . $ranks['Admin'] . '">Admin</option>
<option value="' . $ranks['User'] . '">User</option>
</select>';
Then use those values when building the SQL.