I am taking a php class in college as an elective...I have an assignment to take four numeric inputs from the user, assign them to
session variables, echo them out on a new page within a table. What I can't figure out is how to keep the amounts from resetting..I need for the user to be able to "add more to cart" so to speak. here is the code.
INPUT FIELDS (fruity.php)
<h1>Welcome to the Client & Server Side Fruit Store</h1>
<div id="fixedcontainer">
<form action="fruitbasket.php" method="post">
<div class="fruit"><img src="bananas.jpg" alt="bananas mon!" />
<p>Qty: <input type="text" size="2" maxlength="2" name="banana" id="banana" /></p></div>
<div class="fruit"><img src="apples.jpg" alt="apples mon!" />
<p>Qty: <input type="text" size="2" maxlength="2" name="apple" id="apple" /></p></div>
<div class="fruit"><img src="papaya.jpg" alt="papayas mon!" />
<p>Qty: <input type="text" size="2" maxlength="2" name="papaya" id="papaya" /></p></div>
<div class="fruit"><img src="pineapple.jpg" alt="pineapples mon!" />
<p>Qty: <input type="text" size="2" maxlength="2" name="pineapple" id="pineapple" /></p></div>
<input type="submit" value="Add to Fruitbasket" name="fruitsub" />
</form>
</div>
FRUITBASKET.php (this is where I need to keep track of the number of fruits they want..has to be updated if they select continue shopping)
<?php
session_start();
$getbanana=$POST['banana'];
$getapple=$POST['apple'];
$getpapaya=$POST['papaya'];
$getpineapple=$POST['pineapple'];
$SESSION['totbananas'] = $getbanana;
$SESSION['totapples'] = $getapple;
$SESSION['totpapayas'] = $getpapaya;
$SESSION['totpineapples'] = $getpineapple;
echo "<table border='1'>";
echo "<tr>";
echo "<td>Bananas</td><td>Qty=</td><td>" . $SESSION['totbananas'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Apples</td><td>Qty=</td><td>" . $SESSION['totapples'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Papayas</td><td>Qty=</td><td>" . $SESSION['totpapayas'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Pineapples</td><td>Qty=</td><td>" . $SESSION['totpineapples'] . "</td>";
echo "</tr>";
echo "</table";
?>
<a href="fruity.php">Continue Shopping[/url]
</body>
</html>
I think i have to use a statement like this.
if(isset($SESSION['totbananas'])) {
$temp = $SESSION['totbananas'];
$_SESSION['totbananas'] = $getbanana + $temp;
}
but i cannot get it to work..Any help will be greatly appreciated!