Jump to content

[SOLVED] Checkbox deletion??


dustydoc

Recommended Posts

Hey,

 

I'm trying to delete from a list of data using the checkbox method, but I'm experiencing problems attempting to match my ID with checkboxs especially as the ID's will be non-sequential before/after any deletion. All attempts failured and seem now very confusted on the issue. Please help??

 

best N

Link to comment
https://forums.phpfreaks.com/topic/108221-solved-checkbox-deletion/
Share on other sites

 

 

<form method="post" action="delete_docs.php">

 

<?

//$result = mysql_query("SELECT docID FROM docs");

$result = mysql_query("SELECT * FROM docs");

while($rows=mysql_fetch_array($result)){

//$pop = $rows['docID'];

//echo $pop;

?>

<input type="checkbox" name="done[]" id="<? echo $rows['docID']?>" value="<? echo $rows['docID']?>">

<label for="<? echo $rows['docID'] ?> ";>

<? echo $rows['docID'] . ' : ' . $rows['docname']; ?>

</label>

<br />

<?

}

?>

<input type="submit" value="DELETE">

<br><br>

<?

$result = mysql_query("SELECT docID FROM docs");

while($rows=mysql_fetch_array($result)){

$newarray = $rows['docID'];

echo $newarray;

 

}

?>

give all c.boxes a name like "delID[]" and a value of the record ID on that row

<input type="checkbox" name="delID[]" value="$id">
<input type="checkbox" name="delID[]" value="$id">
<input type="checkbox" name="delID[]" value="$id"> 

 

Only selected c.boxes are posted.

 

To process

 

$ids = join (',', $_POST['delID']);
$sql = "DELETE FROM tablename WHERE id IN ($ids)";    

hey Barand, thanks for your time man.

 

Though i keep getting an error on the join (bad conditons or something?), plus the numbers have dissapeared due to using an alias.

 

heres what i've updated to:

 

<form method="post" action="delete_doc.php">

 

<?

$id=$HTTP_POST_VARS['docID'];

$result = mysql_query("SELECT * FROM docs");

while($rows=mysql_fetch_array($result)){

 

?>

<input type="checkbox" name="delID[]" value="$id">

<? echo $rows[$id] . ' : ' . $rows['docname']; ?>

 

<br />

<?

}

$ids = join (',', $_POST['delID']);

$sql = "DELETE FROM docs WHERE docID IN ($ids)";   

mysql_query($sql);

?>

<input type="submit" value="DELETE">

<br><br>

</form>

</body>

</html>

this bit belongs in delete_doc.php, not in the form

$ids = join (',', $_POST['delID']);
$sql = "DELETE FROM docs WHERE docID IN ($ids)";   
mysql_query($sql);

 

The values for the checkboxes need to be that row's id

 

<input type="checkbox" name="delID[]" value="<?php echo  $rows['id']?>">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.