hey guys so I’m trying to delete a row from table which is connected to database using checkbox(and it wouldnt matter if its just one row or multiple rows) but it is not working, as in nothing happens. it doesn’t delete, no errors or warnings appear just a refresh.
<form class="button-wraps" method="post" action="contact_data.php">
<a href="add_contact.php"><input type="button" id="add_contact" name="add_contact" value="Add Contact"/></a>
<input type="submit" id="del_contact" name="del_contact" value="Delete Contact"/>
</form>
<form method="post" action="contact_data.php">
<table class="contact-list-table">
<thead>
<tr>
<th >Salutation</th>
<th>Name</th>
<th>House Address</th>
<th>Email Address</th>
<th>Telephone No.</th>
<th>Office No.</th>
</tr>
</thead>
<tbody>
<?php
require "connection.php";
$check = mysql_query("SELECT * FROM contact") or die(mysql_error());
$count=mysql_num_rows($check);
if($count > 0)
{
while($rows = mysql_fetch_array($check))
{
$salutation = $rows['salutation'];
$firstname = $rows['fname'];
$lastname = $rows['lname'];
$houseno = $rows['houseno'];
$streetname = $rows['streetname'];
$postcode = $rows['postcode'];
$city = $rows['city'];
$state = $rows['state'];
$country = $rows['country'];
$tel = $rows['tel'];
$off = $rows['off'];
$email = $rows['email'];
$id = $rows['contact_id'];
echo
"<tr>
<td ><input type='checkbox' name='check[]' class='check' value='$id'>$salutation</td>
<td>$firstname $lastname</td>
<td>$houseno $streetname, $postcode, $city, $state, $country</td>
<td>$email</td>
<td>$tel</td>
<td>$off</td>
</tr>";
}
}
else
{
echo
"<tr>
<td colspan='6'>Contact Database is empty.</td>
</tr>";
}
?>
</tbody>
<?php
if (isset($_POST['del_contact']) && isset($_POST['check']))
{
foreach($_POST['check'] as $del_id)
{
$del_id = (int)$del_id;
$sql = "DELETE FROM contact WHERE contact_id = $del_id";
mysql_query($sql);
}
}
?>
</table>
</form>
‘del_contact’ is disabled unless a checkbox is checked.
any help is much appreciated.