Getting checkbox values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nodda4me
Forum Newbie
Posts: 12
Joined: Sun Jun 18, 2006 6:57 pm

Getting checkbox values

Post 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){

}
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Try: $_GET or $_POST
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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";
 }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It should be noted that checking for the submit button can lead to false negatives due to some browsers not submitting it.
Post Reply