I've having some problems trying to get a section of code to work concerning checkboxes in php. here's my code to create the checkboxes:
<?php
include "header.php";
function main($plb_id) {
global $xoopsDB, $xoopsUser;
$result = $xoopsDB->query("select * from ".$xoopsDB->prefix('box_plbu')." where plb_id = $plb_id");
$getRowsNum = $xoopsDB->getRowsNum($result);
$count = 0;
if ($getRowsNum > 0) {
?>
<html>
<body background="images/pop_bg.gif">
<form name="remove" id="remove" action="plb_members.php?func=remove" method="post">
<table background="images/pop_bg.gif">
<tr>
<td>Name</td>
<td>Remove</td>
</tr>
<?php
while (list($plbu_id, $plb_id, $trail_name) = $xoopsDB->fetchRow( $result)) {
echo "<tr>\n";
echo " <td>$trail_name</td>\n";
echo " <td><input type=\"checkbox\" name=\"tbr[]\" value=\"$plbu_id\"></td>\n";
echo "</tr>\n";
$count++;
}
echo "<tr>\n";
echo " <td><input type=\"submit\" name=\"remove\" id=\"remove\" value=\"Remove\"> <input type=\"hidden\" name=\"count\" id=\"count\" value=\"$count\"></td>\n";
echo "</tr>\n";
} else {
?>
<html>
<body background="images/pop_bg.gif">
<table background="images/pop_bg.gif">
<tr>
<td>None</td>
<td> </td>
</tr>
<?php
}
?>
</table>
</body>
</html>
<?php
}
function remove() {
$count = $GLOBALS['count'];
if(is_array($_POST["tbr"])){
foreach($_POST["tbr"] as $d){
array_push($queries,"DELETE FROM table WHERE id=" . intval($d));
}
}
}
switch($func) {
default:main($plb_id); break;
case "remove":remove(); break;
}
?>
That works just fine, pulling the names from the database and displaying them with a checkbox by thier side.
The next part is that in the remove function, I want to loop through the array and if the checkbox is checked, delete the corresponding entry from the database. The current remove function is just something I scarffed fro the Net.
So, can anyone help me figure this one out?