Okay, reading through your code, I don't see anywhere where you add anything else to your cart. Also, it doesn't make sense to store a counter in your session when the counter just holds the size of an array ALSO in the session. Why not just calculate the size of the array?
Here's a simple rewrite of showcart.php:
<?php
session_start();
$id = $_GET['id'];
$price = $_GET['price'];
$name = $_GET['basket']; // why is this named "basket" instead of "name"??
if (! isset($_SESSION['basket']))
{
$_SESSION['basket'] = array();
}
$_SESSION['basket'][] = array('id' => $id,
'price' => $price,
'name' => $name);
// okay. no problem.
if (!empty($_SESSION['basket']))
{
echo "<p>\n";
echo "basket contains<br />\n";
foreach($_SESSION['basket'] as $basket_item)
{
echo $basket_item['id'] . ' '
. $basket_item['name'] . ' '
. $basket_item['price'] . "\n";
echo '<br>';
}
}
?>
<a href="javascript
:history.back()">Back to books</a>
</body>
</html>
It still needs to be cleaned up (include all the proper missing HTML tags like <html><head><body> etc...), but that's an easy exersize I leave to you.
Take care,
Nik
http://www.bigaction.org/