-1

The button delete is working fine it's just that it says that 'record deleted successfully' but it wasn't deleted at all at the table and database.

Here's my code for delete query

<?php require_once('process.php');
if(isset($_GET['id'])) {
$sql = "DELETE FROM tbl_oda_request WHERE id=".$_GET['id'];
$mysqli->query($sql);
echo 'Record deleted successfully.'; }?>

delete button

<td><button class='btn btn-danger delete'>Delete</button></td>

my script

<script type="text/javascript">
    $(".delete").click(function(){
        var id = $(this).parents("tr").attr("id");
        if(confirm('Are you sure to delete this record ?')) {
            $.ajax({
                url: 'delete_oda_req.php',
                type: 'GET',
                data: {id: id},
                error: function() {
                  alert('Something is wrong, couldnt delete record');
                },
                success: function(data) {
                    $("#" + id).remove();
                    alert("Record delete successfully.");  
                }
            });
        }
    });
</script>

1 Answers1

-1

Dump your $_GET variable. Has it an id?

Note: You should not add the id to the string. It cause security issues. see this post

Dikkepanda
  • 21
  • 1
  • 8