php - How can I send over multiple check box checks in POST to be deleted from a database? -
i've been trying think of way this. want users can check off items, hit submit , goes code on next page , deletes of checked items database. problem 1 in post sending on last checked item. here how have set right now.
echo "<form name='fm1' method ='post' action ='displaydelete.php' > ";
//draws table headers echo ""; echo ""; echo "fund number "; echo "hours "; echo "percentage"; echo "delete"; echo ""; //while there query results data pushed table cells while ($row = mysql_fetch_array($queryresult2)) { $hours = $row['hours']; $percentage = $hours / 160 * 100;
echo "<tr>"; echo "<td>"; echo $row['funnumber']; echo "</td>"; echo "<td>"; echo $hours; echo "</td>"; echo "<td>"; echo $percentage ."%"; echo "</td>"; echo "<td>"; echo "<input type='checkbox' name='id' value='$row[id]'/>"; echo "</td>"; echo "</tr>"; } //end of tabel echo "</table>";
echo" "; echo "";
what push of items variable , maybe delete them way. i'm not sure how handle multiple deletes. i'm doing delete else if helps any.
$query = "delete users
where ninenumber = '$ninenumber'"; $result = mysql_query($query) or die("query failed: " .mysql_error());
mysql_close($conn);
instead of this:
echo "<input type='checkbox' name='id' value='$row[id]'/>";
you need this:
echo "<input type='checkbox' name='id[]' value='$row[id]'/>";
note difference. added []
after input name. tells client , server there multiple inputs name. $_post['id']
array can loop through on next page.
foreach ($_post['id'] $checkbox) { // delete users ninenumber = $checkbox }
isset
, is_array
, , mysql_real_escape_string
omitted brevity.
Comments
Post a Comment