如何使用ajax和php进行删除功能

I dont know whats wrong with my code but i have this error Notice: Undefined index: delete

I want to make delete function with CRUD

here is my php code:

    if($_POST["delete"])
{
    $query = '
    DELETE FROM `users` WHERE id = :id
    ';
    $statement = $connect->prepare($query);
    $statement->execute(
        array(
            ':id'              => $_POST['id']
        )
    );
    $result = $statement->fetchAll();
    if(isset($result))
    {
        echo '<div class="alert alert-fill-danger" role="alert">User Deleted!<div>';
    }
}

and here is the AJAX function

$(document).on('click', '#delete', function(){
       var id = $(this).data('id');
       $('#message').html('');

       Swal.fire({
  title: 'Are you sure?',
  text: "You want to delete this user?",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes'
  }).then((result) => {
       if (result.value){
        $.ajax({
         url:'/auth/action',
         method:'POST',
         data:{id:id},
         success:function(data)
         {
          if(data != '')
          {
           load_user_data();
           $('#message').html(data);
          }
         }
        });
                      Swal.fire(
      'User Deleted!',
      '',
      'success'
    )
       }
       })

      });

I dont know what i missed here but the function in php is not working??

Perhaps try the following: Test for the availability of the variables before trying to use them in PHP. Also - there will be no recordset so fetchAll will not work.

if( isset( $_POST['delete'], $_POST['id'] ) {
    ob_clean();
    $id=$_POST['id'];

    $query = 'DELETE FROM `users` WHERE id = :id';
    $statement = $connect->prepare( $query );
    $result = $statement->execute( array( ':id' => $id ) );

    if( $result && $statement->rowCount() > 0 ){
        echo '<div class="alert alert-fill-danger" role="alert">User Deleted!<div>';
    }
    exit();
}

here is the answer to my problem :D

var action = 'delete';

I just add this code under the id in ajax

if($_POST["action"] == 'delete')
    {
        $query = '
        DELETE FROM `users` WHERE id = :id
        ';
        $statement = $connect->prepare($query);
        $statement->execute(
            array(
                ':id'              => $_POST['id']
            )
        );
        $result = $statement->fetchAll();
        if(isset($result))
        {
            echo '<div class="alert alert-fill-danger" role="alert">User Deleted!<div>';
        }
    }