eddy
01-20-2003, 08:55 AM
i have been trying to use session in php 4.2.3, i have used a very basic shopping cart, i have been unable to add things to the cart, it seems to work in earlier versions but not this one, does any one know why not
<?php
error_reporting(1); // suppress warning messages
session_start(); // Initialise session
session_register("trolleyContents"); // Register our variables
?>
<html><head><title>PHP session example</title>
</head><body>
<h2 align="center">Shopping trolley </h2>
<form method="post" action="SessionTrolley.php?<?=SID?>">
Choose an item: </p>
<input type="radio" name="choice" value="camera" /> camera<br />
<input type="radio" name="choice" value="snorkel" /> snorkel<br />
<input type="radio" name="choice" value="octopus" /> octopus<br />
<input type="radio" name="choice" value="cuddly toy" /> cuddly toy<br /><br />
<input type="submit" name="submit" value="Add to the trolley" />
<input type="submit" name="clear" value="Empty the trolley" /><br />
</form>
<?php
if ((!$trolleyContents && !$choice) || $clear) {
$trolleyContents = "";
echo "<p>Trolley currently empty</p>";
} else {
if ( $choice ) $trolleyContents = $trolleyContents . "<li>$choice</li>";
echo "<p>Trolley contains:</p>";
echo "<ul>$trolleyContents</ul>";
}
?>
</body></html>
<?php
error_reporting(1); // suppress warning messages
session_start(); // Initialise session
session_register("trolleyContents"); // Register our variables
?>
<html><head><title>PHP session example</title>
</head><body>
<h2 align="center">Shopping trolley </h2>
<form method="post" action="SessionTrolley.php?<?=SID?>">
Choose an item: </p>
<input type="radio" name="choice" value="camera" /> camera<br />
<input type="radio" name="choice" value="snorkel" /> snorkel<br />
<input type="radio" name="choice" value="octopus" /> octopus<br />
<input type="radio" name="choice" value="cuddly toy" /> cuddly toy<br /><br />
<input type="submit" name="submit" value="Add to the trolley" />
<input type="submit" name="clear" value="Empty the trolley" /><br />
</form>
<?php
if ((!$trolleyContents && !$choice) || $clear) {
$trolleyContents = "";
echo "<p>Trolley currently empty</p>";
} else {
if ( $choice ) $trolleyContents = $trolleyContents . "<li>$choice</li>";
echo "<p>Trolley contains:</p>";
echo "<ul>$trolleyContents</ul>";
}
?>
</body></html>