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
Nodda4me
Forum Newbie
Posts: 12 Joined: Sun Jun 18, 2006 6:57 pm
Post
by Nodda4me » Sat Feb 24, 2007 12:01 pm
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:
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Sat Feb 24, 2007 12:22 pm
Try: $_GET or $_POST
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Sun Feb 25, 2007 9:30 am
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";
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 25, 2007 10:30 am
It should be noted that checking for the submit button can lead to false negatives due to some browsers not submitting it.