Submit updates to a mysql table through checkboxes

Posted on 2008-11-18
Last Modified: 2012-05-05
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

Question by:Catcherman16
    LVL 15

    Accepted Solution

    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

    LVL 107

    Assisted Solution

    by:Ray Paseur
    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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now