Submit updates to a mysql table through checkboxes

I am having a little trouble. what i am trying to do is retrieve a list of unauthorized users, and list them (no problem, got that part taken care of).

Where i am running into trouble is after listing the unauthorized users in a table, i want the admin to be able to click a checkbox next to each of the user he wants to authorize and then update the users authorization status.

How would i go about implementing this?
	  if($_SESSION['permissions'] == "2")
$con = mysql_connect($databse, $user, $dbpass);
if (!$con)
  die('Could not connect: ' . mysql_error());
mysql_select_db($table, $con);
$result = mysql_query("SELECT * FROM Users WHERE authorized = '0'");
echo "<table width='200' bgcolor='000000' border='1'>
<th width='25%'>Username</th>
<th width='7%'>Authorize</th>
while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" 
  <form name="authorize" action="authorize.php" method="post">
  <input type="radio" name="authorize" />
  echo "</tr>";
echo "</table>";
	<input type="submit" name="Submit" value="Authorize" />

Open in new window

Who is Participating?
quincydudeConnect With a Mentor Commented:
The idea is like putting a checkbox (all with the same name) next to each username

 <input type="checkbox" name="userlist[]" value="$userid"> , where $userid is the user of each username.

After submit the form , you can get the selected list by

foreach($_POST['userlist'] as &$value) {
    echo $value;

Open in new window

Ray PaseurConnect With a Mentor Commented:
Radio buttons are mutually exclusive - even if you have 5 of them, you get no more than one in the $_POST input.  You can get zero, if the client selected nothing.

Checkboxes are not mutually exclusive - You can get zero or more (up to the total number of checkboxes) depending on what the client selected.  A checkbox that is not checked does NOT come through in the $_POST input.  Why is this important?  

If you put up a form with a checkbox that is checked (ie: a member in good standing) and the client un-checks it, the checkbox will be absent in $_POST - you can't check for a value of "off" or something helpful like that.  Instead you have to know that the checkbox exists and know that its absence in $_POST means a change of state.  A nuisance, but forewarned is forearmed!

I think when you are testing with these things it is helpful to put this into the script: var_dump($_POST);

best of luck with your project, ~Ray
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.