What is the best practice for triggering a MySQL deletion operation from a PHP output list?

When triggering a MySQL deletion operation from a PHP output list, it is best practice to use a form with a hidden input field containing the ID of the item to be deleted. This hidden input field can be dynamically generated within the output list using a loop. When a delete button is clicked, the form is submitted to a PHP script that processes the deletion operation based on the ID passed through the hidden input field.

<!-- Output list with delete buttons -->
<?php
// Assuming $items is an array containing the items to display
foreach($items as $item) {
    echo "<div>{$item['name']} <form method='post' action='delete.php'><input type='hidden' name='id' value='{$item['id']}'><button type='submit' name='delete'>Delete</button></form></div>";
}
?>

<!-- delete.php script -->
<?php
// Assuming you have established a MySQL connection
if(isset($_POST['delete'])) {
    $id = $_POST['id'];
    $sql = "DELETE FROM table_name WHERE id = $id";
    if(mysqli_query($conn, $sql)) {
        echo "Record deleted successfully";
    } else {
        echo "Error deleting record: " . mysqli_error($conn);
    }
}
?>