how to delete multiple selected data in php?

By December 14, 2011 PHP
sample.php

<?php
if($_POST[‘delete’]==’Delete Slected’){
    for($i=0;$i<$count;$i++){
        $del_id = $checkbox[$i];
        $sql = “delete from need_workshop where id=’$del_id'”;
        $result = mysql_query($sql);
    }
}
?>
<form name=”frmdelete” method=”post” action=””>
<table width=”100%”>
<tr>
<td colspan=”8″ align=”Left” bgcolor=”#FFFFFF”><input name=”delete” type=”submit” id=”delete” value=”Delete Slected”></td>
</tr>
<tr>
 <td id=”heading”>Select</td>
 <td id=”heading”>Name</td>
 <td id=”heading”>College</td>
 <td id=”heading”>Contact</td>
 <td id=”heading”>E-mail</td>
 <td id=”heading”>Worksdop Type</td>
 <td id=”heading”>Date</td>
 <td id=”heading”>Remarks</td>
 <td id=”heading”>BestTimeToCall</td>
 <td id=”heading”>Delete</td>
 <td id=”heading”>Edit</td>
</tr>
<?php

while($row=mysql_fetch_array($rs_get_seminar))
{
?>

    <tr>
    <td id=”content”><input name=”checkbox[]” type=”checkbox” id=”checkbox[]” value=”<? echo $row[‘id’]; ?>”></td>
    <td id=”content” width=”10%”><?=$row[‘name’] ?></td>
    <td id=”content”><?=$row[‘college’] ?></td>
    <td id=”content”><?=$row[‘contact’] ?></td>
    <td id=”content”><?=$row[’email’] ?></td>
    <td id=”content”><?=$row[‘workshop_type’] ?></td>
    <td id=”content”><?=$row[‘modified’] ?></td>
    <td id=”content”><?=$row[‘remarks’]?></td>
    <td id=”content”><?=$row[‘timetocall’]?></td>       
    <td id=”content”><a href=”delete.php?id=<?=$row[‘id’]?>”>Delete</a></td>
    <td id=”content”><a href=”edit.php?id=<?=$row[‘id’]?>”>Edit</a></td>
    </tr>
<?php
}
?>
<tr>
<td colspan=”8″ align=”Left” bgcolor=”#FFFFFF”><input name=”delete” type=”submit” id=”delete” value=”Delete Slected”></td>
</tr>
</table>
</form>

delete.php

<?php
$id = $_REQUEST[‘id’];
$con = mysql_connect(“localhost”,”root”,””)or die(mysql_error());
mysql_select_db(“tricksco_tritech”,$con) or die(mysql_error());
$sql = ‘delete from need_workshop where id = ‘. $id;
$result = mysql_query($sql)
or die (“Could not execute query: “.mysql_error());
header(‘Location:PATH’);
?>

Leave a Reply

7 + = 13

Open chat
💬 Need help?