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
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;

 

}

?>

Link to comment
Share on other sites

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)";    

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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']?>">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.