I borrowed some code from someone on here to try and learn about sessions. I've got a little shopping basket working:
http://www.dan-jones.org.uk/basket/ and i need to know how to remove items from the session array... here is the code for the basket...
<?php
session_start();
?>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<?
if (isset($_REQUEST['id'])){
$id = $_GET['id'];
$price = $_GET['price'];
$name = $_GET['name'];
if (!isset($_SESSION['basket']))
{
$_SESSION['basket'] = array();
}
$_SESSION['basket'][] = array('id' => $id,
'price' => $price,
'name' => $name);
if (!empty($_SESSION['basket']))
{
?>
<title>Cart</title><body bgcolor="#99CC99">
<p class="cart">Session ID: <? echo session_id() ?> </p>
<table width="400" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF" class="border">
<tr>
<td colspan="3" class="header">Basket Contains</td>
</tr>
<tr valign="top" class="cart">
<td><strong>Item</strong></td>
<td width="50"><strong>Cost</strong></td>
<td width="50"> </td>
</tr>
<tr valign="top" class="cart">
<td colspan="3"><img src="line.gif" width="100%" height="1"></td>
</tr>
<? ;
foreach($_SESSION['basket'] as $basket_item)
{
?>
<tr valign="top" class="cart">
<td><? echo $basket_item['name'] . ' ' ?></td>
<td width="50">£<? echo $basket_item['price'] . ' ' ?></td>
<td width="50"><a href="<? unset($_SESSION['basket'][$id]); ?>">Remove</a></td>
</tr>
<tr valign="top" class="cart">
<td colspan="3"><img src="line.gif" width="100%" height="1"></td>
</tr>
<? ; } } ?>
<tr valign="top" class="cart">
<td><div align="right">Total</div>
</td>
<td width="50">£<? echo $total; ?></td>
<td width="50"> </td>
</tr>
</table>
<p align="center"><a href="item.php" class="cart">Continue Shopping</a>
<p align="center"><a href="close.php" class="cart">Start over</a>
</p>
<p> </p>
</body>
</html>
It's probably a bit messy because i'm new to all this....
Hope someone can help!!