Page 1 of 1

Getting checkbox values

Posted: Sat Feb 24, 2007 12:01 pm
by Nodda4me
I have a table that lists the users of my website and the status of them, either 1 (enabled) or 0 (disabled).

For every user I have a checkbox:

Code: Select all

echo "<input name='checkbox[]' type='checkbox' id='checkbox[]' value='$r[id]'";
	if ($r[status] == "1") {
		echo " checked='checked'";
	}
echo ">";
After I submit, how do I get the value of them? I want it to update each user:

Code: Select all

$sql = "UPDATE `Users` SET `active`='" . $val . "' WHERE id='$id'";

It will all be under:

Code: Select all

if($Submit){

}

Posted: Sat Feb 24, 2007 12:22 pm
by nickvd
Try: $_GET or $_POST

Posted: Sun Feb 25, 2007 9:30 am
by anjanesh

Code: Select all

if (isset($_POST['Submit']))
 {
        $cond = "";
        while (list($k, $v) = each($_POST['checkbox']))
         {
                $cond .= "`id` = '$v' OR ";
         }
        $cond = substr($cond, 0, -4);
        $sql = "UPDATE `Users` SET `active` = '$val' WHERE $cond";
 }

Posted: Sun Feb 25, 2007 10:30 am
by feyd
It should be noted that checking for the submit button can lead to false negatives due to some browsers not submitting it.