html - How can I remove all items from the cart in PHP?

one text

Solution:

It looks like you you not linking properly to your remove_all.php file. Try this:

<form action="/remove_all.php" method="post" class="cart-items">
<button type="submit" value="Очистить всё" name="remove_all" class="btn btn-danger mx-2">Очистить всё</button>
</form>

Also in your PHP file, you do not need to mix PHP and js - simply change header as following:

<?php
    if (isset($_POST['remove_all'])){
            unset($_SESSION['cart']);
            // echo "<script>window.location = 'cart.php'</script>";
            header("Location: cart.php");
        }
?>

Source