Help With HTML Select and MySQL Delete

The code is posted here: http://codepad.org/Fck5s2zz
The same code is also posted below.

[text]
What I am trying to do is create a function that will allow me to delete a user from my mysql database.

I have an HTML select that outputs the username(s) using the function get_admin_username()
(The function is posted below)

There is also a HTML form I am using to make this happen.
(Also posted below)

In other words I would select the user I would like to delete, and click submit which will then delete the user from the database.

The problem I am having is I do not know how to pass values from the HTML select, or the form, or even use the submit button value.

I am not sure If I need to create a function to achieve this.
Basically I don’t know what to do this at all for that matter.

I thought I might have gotten close but I thought wrong, and failed.
I was told (in the php irc) that my method was way off and wrong but was given no help after that.

I do have an example to show you of how I tried to accomplish this, but being told that I was wrong I did not feel that it was even worth posting it.

I am lost and have been at this for two days now. I am a noobe but I do understand allot (I think).

Someone, anyone, please help.

Thank You,

Ryan
[/text]


<?php

   // Session's Functions
   require_once("../includes/sessions/session.php");

   // Establish A Connection To The Database
   require_once("../includes/connection/connection.php");

   // User Defined Admin Functions
   require_once("includes/functions/admin_functions.php");

   // New User Functions
   //require_once("includes/users/delete_user.php");

   // Confirms If The User Is Logged In
   confirm_logged_in();

   // Document Header
   include("includes/templates/default/header.php");

?>


<?php
   // Gets The Admin Username
   function get_admin_username()
      {
         global $connection;
         $query = "SELECT * FROM administration_users ";
         $query .= "ORDER BY username";
         $admin_user_set = mysql_query($query, $connection);
         confirm_query($admin_user_set);

         while ($admin_users = mysql_fetch_array($admin_user_set))
            {
               echo "<option value=\\"username" . "\\">" . $admin_users['username'] ."\
  ";
            }
      }
?>


      <table id="structure">
         <tr>
            <td id="navigation">
               <a href="../staff.php">Return To Staff Menu</a>
               <a href="admin_content.php">Return To Admin Menu</a>
<br />
<br />
               <ul class="menu">
                  <li class="pages"><a id="page_menu" href="new_user.php">Add New User</a></li>
                  <li class="pages"><a href="edit_user.php">Edit User</a></li>
                  <li class="pages"><a href="list_users.php">List Users</a></li>
                  <li class="pages"><a href="delete_user.php">Delete User</a></li>
               </ul>
            </td>

            <td id="page">
               <h2>Remove User</h2>

<br />

               <form action="delete_user.php" name="delete_user" method="post">
                  <table>
                     <tr>
                        <th class="field_name field_padding_user_name">User Name: &nbsp;</th>

                        <td>
                           <select id="select_username" name="username_select">
                              <?php echo get_admin_username();?>
                           </select>
                        </td>
                     </tr>

                     <tr>
                        <td class="delete_user_submit" colspan="2"><input type="submit" name="submit" value="Delete User"
                             onclick="return confirm('Are You Sure You Want To Delete This User?');"/></td>
                     </tr>
                  </table>
               </form>
            </td>
         </tr>
      </table>


<?php

   // Document Footer
   include("includes/templates/default/footer.php");

?>

form.php


<form action = "delete_user.php" method="post">
<input type=select name="selected_user" id = "selected_user">
<select>bob</select>
<select>ted</select>
<select>carol</select>
<select>alice</select>
</select>
<input type=submit>
</form>

delete_user.php



/*Security checks left out for brevity*/
$username = $_POST['selected_user'] ;

£sql= 
"DELETE from
users where 
username = '$username'"

Essentially this is how it works.

Get the bare bones working first, then add on JS client side checks, tables, styles etc.

This is not a good subject for a poll (I did the same when starting out, don’t feel too bac)

OK. I have gotten the result I wanted. (To delete the selected user).
However is this a proper way to write the code?


<?php

	// Gets The Admin Username
	function get_admin_username() 
		{
			global $connection;
			$query = "SELECT * FROM administration_users ";
			$query .= "ORDER BY username";
			$admin_user_set = mysql_query($query, $connection);
			confirm_query($admin_user_set);

			while ($admin_users = mysql_fetch_array($admin_user_set)) 
				{
					echo "<option value=\\"username" . "\\">" . $admin_users['username'] ."\
  ";
				} 
		}



	// Deletes The Selected User
	if (isset($_POST['submit']) && 'username')
		{
			$query= mysql_query("DELETE FROM administration_users WHERE username={$_POST['username_select']} LIMIT 1") or die(mysql_error());
		}

?>

Technically you shouldn’t need the global $connection; or second parameter in the query call; a script in execution will automatically use the last-opened-DB-connection when mysql_query is called.
You forgot to close your <option> tag.
DELETE shouldnt need a LIMIT since a username should be unique.

I would recommend including the connection paramater in mysql_query() even though it is optional. You could pass the connection variable to the function and this eliminates the possibility that php might not be able to find the last opened connection for some reason.

Also, if you have a large number of users, I wouldn’t use a <select>. I would normally display a fixed number of users on a page, with pagination, with a checkbox beside each user so you can delete more than one user at a time if needed. You could also provide a search box on the top of the page to search for a user(s) rather than going from page to page until they appear.