Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
- <table border="1" cellpadding="4">
- <tr>
- <th>Id</th>
- <th>Name</th>
- </tr>
- <?php
- include('connect.php');
- $getQuery = "SELECT id,username,admin FROM tutorial_users ORDER BY id ASC";
- $getResult = mysql_query($getQuery) or die("Query not executed");
- while (list($id, $userName, $admin) = mysql_fetch_row($getResult)) {
- ?>
- <?php
- $checked = ($admin == 1) ? 'checked="checked"' : '';
- ?>
- <tr align="center">
- <td><?php echo $id; ?></td>
- <td><?php echo $userName; ?></td>
- <td><?php echo "<input type='checkbox' name='admin[]' value='$id' $checked>"; ?></td>
- <?php } ?>
- <tr>
- </table>
- <p>
- <input type="submit" name="submit" value="Update Role">
- </p>
- </form>
- <?php
- $updated = FALSE;
- if (isset($_POST['submit'])) {
- $admin = $_POST['admin'];
- $admin = join(",", $admin);
- $admin = "(" . $admin . ")";
- $defaultQuery = "UPDATE tutorial_users SET admin=0";
- $defaultResult = mysql_query($defaultQuery);
- $upQuery = "UPDATE tutorial_users SET admin=1 WHERE id IN $admin";
- echo $upQuery;
- $upResult = mysql_query($upQuery);
- $updated = TRUE;
- }
- ?>
- <option value="the_value_of_option" <?php if(isset($_POST['something']) && ($_POST['something'] == 'the_value_of_option')){echo "selected";}?> >Label of option</option>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement