Delete Data without Refreshing Page
Posted: 14 Jan 2020, 18:19
Happy New Year Chief.... My first two weeks I spended on bed due to illness
I wanna use a script but it does not delete the item from my sql record
I think it does not detect the id in this javascript
&nd here is the code delete_member.php
I hope you can help me out with this one ????
I wanna use a script but it does not delete the item from my sql record
Code: Select all
<?php
$result = $database->prepare ("SELECT * FROM groups ");
$result ->execute();
for ($count=0; $row_member = $result ->fetch(); $count++){
$id = $row_member['post_id'];
?>
<tr class="delete_mem<?php echo $id ?>">
<td><?php echo $row_member['user_name']; ?></td>
<td><?php echo $row_member['group_title']; ?></td>
<td><?php echo $row_member['group_date']; ?></td>
<td width="80">
<a class="btn btn-danger" id="<?php echo $id; ?>">Delete</a>
</td>
</tr>
<?php } ?>
Code: Select all
<script type="text/javascript">
$(document).ready(function() {
$('.btn-danger').click(function() {
var id = $(this).attr("id");
if (confirm("Are you sure you want to delete this Member?")) {
$.ajax({
type: "POST",
url: "delete_member.php",
data: ({
id: id
}),
cache: false,
success: function(html) {
$(".delete_mem" + id).fadeOut('slow');
}
});
} else {
return false;
}
});
});
</script>
Code: Select all
<?php
include ('database.php');
$id = $_GET['id'];
$delete_data"delete from groups where post_id = '$id' ";
$database->exec($delete_data);
?>