i'm tyring to delete some records from my database but without going to the delete.php file or refreshing the page.
i tried this code:
lieferant.php
<td> <?php echo $row['lieferantID']; ?> </td>
<td> <?php echo $row['lieferantname']; ?> </td>
<td> <?php echo $row['kontakt']; ?> </td>
<td> <?php echo $row['mail']; ?> </td>
<td> <button type="button" id="<?php echo $row['lieferantID']; ?>" class="delete-btn">Delete</button></td>
<script type="text/javascript" >
$(function() {
$(".delete-btn").click(function() {
var del_id = $(this).attr("id");
var info = {"lieferantID": del_id};
if (confirm("Are you sure?")) {
$.ajax({
type : "POST",
url : "delete.php", //URL to the delete php script
data : info,
success : function() {
}
});
$(this).parents(".record").animate("fast").animate({
opacity : "hide"
}, "slow");
}
return false;
});
});
</script>
delete.php
$lieferantID=$_POST['lieferantID'];
$delete=mysqli_query($connection,"DELETE FROM 'lieferant' WHERE lieferantID='$lieferantID'");
$result = mysqli_query($delete) or die(mysqli_error());
Unfortunetely it doesn't work. When i put the ID of the row manuelly in the query it will be deleted without going to the delete.php, but still i have to refresh the page to see that the record is gone, so my question is:
1.how can i pass the 'lieferantID' (the ID of the row) to my delete.php, so that it works automatically 2.how can the page "refresh" itself?
thanks for any help :)