Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2006, 12:43 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session issues

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">&nbsp;</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">&pound;<? 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">&pound;<? echo $total; ?></td>
          <td width="50">&nbsp;</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>&nbsp;</p>
</body>
</html>


It's probably a bit messy because i'm new to all this....

Hope someone can help!!
 
Old September 23rd, 2006, 04:14 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

unset($_SESSION['basket']) should work.

Try it.






Similar Threads
Thread Thread Starter Forum Replies Last Post
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
IE Issues iPagan BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 April 1st, 2007 04:11 AM
Still Having Issues slas7713 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 October 27th, 2006 02:59 PM
For-each issues hiskeyd XSLT 1 February 27th, 2006 08:01 PM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.