trying to call php function on button click to delete row from db which i'm looping... need to pass button tag id attribute to the function. cant get it work
$('button').click(
function(){
var id = $(this).attr('id');
$.ajax({
url: "ins.php",
type: "POST",
data: id,
success: function(data){
}
});
});
// html button in table to delete a row
<td><button id='.$i.' name="delete"><img src="delete.png"></button></td>
// ins.php
if (isset($_POST['delete'])){
DB_delete($conn, $_POST['delete']);
}
// function that deletes the row
function DB_delete($conn,$id){
$sql = "DELETE FROM person WHERE id = ?";
$stmt=$conn->prepare($sql);
$stmt->bind_param('i',$id);
$stmt->execute();
$stmt->close();
}