so, i know how to get all the values of checked checked boxes
it goes like this :

foreach($_POST['checkbox'] AS $value) {
echo $value . "<br>";
}

but how do i get the values of all the unchecked checkboxes?

my form looks like this:

<FORM METHOD="post">
<INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="1">1<br>
<INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="2">2<br>
<INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="3">3<br>
<INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="4">4<br>
<INPUT TYPE="submit" NAME="send" VALUE="Send">
</FORM>

right now i can only update the table with checked values but when the user unchecks something the value of that checkbox remains 1 or checked.

is there a way to get these values (unchecked)? or do forms even submit these values?

thanks in advance

    Nope, unchecked checkboxes do not get included in the $_POST super global....

      found a workaround. i could acomplish the same thing with an added update query where all rows for id-s (checkbox values) are turned into 0.

      but i don't know how to make this query 🙁

      it should go like ("update modules set access='0' where id!=(now we get all the values from checkbox array with or's in between or something)")

      it should be easy but i just don't seem to find a way to say it.

      anyone?

        did some digging around the boards and found some useful posts.
        got my script working and hope that it will help others with similar problems.

        here goes:

        <?
        include("connect.inc");

        #if submit was pressed
        if (isset($HTTP_POST_VARS['send'])) {

        #foreach will create an error if it is started without any values
        #so, we check if any checkboxes were ticked

        if (isset($_POST['checkbox'])) {

        #lets update the table
        #every row (checkbox value=id) that was ticked will get the value of 1
        foreach($_POST['checkbox'] AS $value) {
        $query = mysql_query("UPDATE table set value='1' where id='$value'");
        }

        #now we'll construct a string that will exclude the id's that were already changed to 1 from our next query
        $query_start = ' WHERE ';

        		foreach($_POST['checkbox'] AS $value) {	
        		$query_array[] = "id!= '" . $value . "'";
        		}

        #create the query string by combining the query array using "AND" as a delimiter
        #and then update the unchecked values to 0
        if ($query_array) {
        $query_string = $query_start . implode(' AND ', $query_array);
        $query2 = mysql_query("UPDATE table set value='0'$query_string");
        }

        #if no checkboxes weren't ticked (or were unticked) bu tsubmit was pressed...
        #we will update all values to 0
        } else {

        $query3 = mysql_query("UPDATE table set value='0'");
        }

        #that's it
        }
        ?>
        <html>
        <head>
        <title>Untitled</title>
        </head>
        <body>
        <FORM METHOD="post" action="test.php">
        <INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="1">1<br>
        <INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="2">2<br>
        <INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="3">3<br>
        <INPUT TYPE="checkbox" NAME="checkbox[]" VALUE="4">4<br>
        <INPUT TYPE="submit" NAME="send" VALUE="Send">
        </FORM>
        </body>
        </html>

          a year later

          why don't you just run a query first and set everything to 0 then loop through the checked arrays and change the checked ones to 1?

          A.

            Write a Reply...