i have a html table which displays columns -client name,staff name, matter and delete. my delete column contains only buttons for each row.And my data base contains columns id,date ,client name, staff name and matter.My database does not contain delete column,it is just displayed in my html table.now i want to delete particular row on click of corresponding delete button in that row.just check out my jquery code and sql code and let me know why is it not working? jquery code-
$(document).ready(function()
{
$('input[type=button]').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().parent().attr('id');
var data = 'id=' + id ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
});
my sql code -
<?php
include 'db.php' // DB Connection
if($_POST['id'])
{
$ID = mysql_escape_string($_POST['id']);
$sql = "DELETE FROM `newdata` WHERE id = '$ID'";
mysql_query($sql);
}
?>
and my html goes like this-
<table class="footable" data-filter="#filter" id="tableresult">
<thead>
<th>Client name</th>
<th>Staff name</th>
<th>Matter</th>
<th> Delete</th>
</thead>
<tr id="<?php echo $id; ?>" class="edit_tr">
<td class="edit_td" >
<span id="client_<?php echo $id; ?>" class="text"><?php echo $clientname; ?></span>
<input type="text" value="<?php echo $clientname; ?>" class="editbox" id="client_input_<?php echo $id; ?>" />
</td>
<td class="edit_td">
<span id="staff_<?php echo $id; ?>" class="text"><?php echo $staff; ?></span>
<input type="text" value="<?php echo $staff; ?>" class="editbox" id="staff_input_<?php echo $id; ?>"/>
</td>
<td class="edit_td">
<span id="matter_<?php echo $id; ?>" class="text"><?php echo $matter; ?></span>
<input type="text" value="<?php echo $matter; ?>" class="editbox" id="matter_input_<?php echo $id; ?>"/>
</td>
<div id ="delete_btn">
<td class="delete_td"><input type="button" id="del" class="btn btn-danger" value="×"></input></td>
</div>
</tr>