Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

note 21748 added to ref.session

0 views
Skip to first unread message

p...@tiv.net

unread,
May 25, 2002, 2:01:50 AM5/25/02
to php-...@lists.php.net
I wrote a tiny "shopping-cart" code when I was learning PHP sessions. (Use ++ instead of =1 to allow more than one product of a kind in the cart).

<?php
session_start();
// - Add
if( isset( $_GET['ADD'] ) ) {
$_SESSION['aBasket'][$_GET['ID']] = 1;
}
// - Remove
if( isset( $_GET['DEL'] ) ) {
unset($_SESSION['aBasket'][$_GET['ID']]);
}
// - Remove All
if( isset( $_GET['EMP'] ) ) {
unset($_SESSION['aBasket']);
}
// - Show
if( isset( $_SESSION['aBasket'] ) ) {
foreach ( $_SESSION['aBasket'] as $key=>$val ) {
echo "$key ";
}
}
?>
<form>
Product:
<input type="text" name="ID">
<input type="submit" name="ADD" value="Add">
<input type="submit" name="DEL" value="Del">
<input type="submit" name="EMP" value="Empty">
</form>

Gregory
http://tiv.net/
--
http://www.php.net/manual/en/ref.session.php
http://master.php.net/manage/user-notes.php?action=edit+21748
http://master.php.net/manage/user-notes.php?action=delete+21748
http://master.php.net/manage/user-notes.php?action=reject+21748

0 new messages