You are over complicating things.
<form method="get" action="">
<input type="hidden" name="cmd" value="emptycart" />
<input type="submit" name="empty_cart_submit" value="Empty Cart" onclick="return confirm('are you sure?');" />
</form>
For a solution without a page reload:
From your main page you want to call a script to unset the $_SESSION
, but rather than reload the page you can use ajax to reload only the cart itself.
Say you have a file which is a sub-view just for the contents of the cart, called in your main page like
<div id="cart-contents">
//with a function
<?php echo get_cart_sub_view(); ?>
//or with an inlude
<?php include('cart_sub_view.php'); ?>
</div>
You can ajax in your new cart contents using jQuery load.
You need a script to generate the html that goes inside the cart, which you can call via ajax (i.e cart_sub_view.php).
After the $_SESSION
unset call, call
$("#cart-contents").load(
'cart_sub_view.php'
);
Which will ajax to the sub view page, and then copy its contents into the cart-contents div.