Forums

PHP

This topic is locked

delete rows using checkboxs

Posted 23 May 2006 23:59:17
1
has voted
23 May 2006 23:59:17 richard mcilvenna posted:
hi, i am desperate to find this solution. i want to delete multiple rows from a database using checkboxes. the code below shows the names of people on the db with a checkbox next to them. i have been trying, using a varety of loops

the form is submitted to itself..


while ($i < $num) {

$name=mysql_result($result,$i,"name";

$id[i]=mysql_result($result,$i,"id";

echo "<tr><td > $name /td>";

echo "<td><input type='checkbox' name='name[]' value='$id[i]'></td></tr>";
$i++;
}

?>

<tr><td><input type="submit" name="submitok" value=" OK " /></td></tr>
</form>
</table>
</center>

<?php

else://if submitted then do

if(isset($_POST['name[]'])) {
$j_size = sizeof(name[]);

for($ii=0;$ii<$j_size;$ii++) {
$key = $j_delete[$ii];

$sql = "DELETE FROM details WHERE id = $key";
mysql_query($sql);

}
}

echo "deleted ";

Replies

Replied 24 May 2006 15:18:02
24 May 2006 15:18:02 Roddy Dairion replied:
Do you get any error message? I solved this prob before when i cam across by submitting all the id passed in the checkbox in n array and i used a for loop to delete them off.
Replied 24 May 2006 21:27:52
24 May 2006 21:27:52 richard mcilvenna replied:
no error message, it just echos deleted but the rows are still there

Reply to this topic