hello everyone,
i'm new to php and i'm having hard time with sessions
i'm trying to create a php file with a drop down menu and when you select an item from the drop down menu, you could retreve it from another page.
for example:
a1.php
<?php session_start();
if(isset($_POST['color']))
{
$_SESSION['blue']='blue';
$_SESSION['red']='red';
$_SESSION['green']='green';
$_SESSION['orange']='orange';
}
?>
<html>
<body>
<form id="shirt" method="post" action="a2.php">
<p>
<select name="Size">
<option value="invalid">Select a size ...</option>
<option value="blue">blue</option>
<option value="red">red</option>
<option value="green">green</option>
<option value="orange">orange</option>
</select>
<br />
<input type="Submit" value="Add" name="Add" />
</p>
</form>
</body>
</html>
when the user chooses a color, it adds it to the session and then when the user clicks add, he is redirected to another page named a2.php which shows the color is added.
if the user goes back to the original page and adds the same color again it shows that he added the item again:
Color: ----------- Quantity:
Red ----------- 2
a2.php
<?php session_start();
$item_id = $_GET[id];
$action = $_GET[action];
switch($action)
{
case "add":
$_SESSION['color'][$item_id]++;
break;
case "remove":
$_SESSION['color'][$item_id]--;
if($_SESSION['color'][$item_id] == 0) unset($_SESSION['color'][$item_id]);
break;
case "empty":
unset($_SESSION['color']);
break;
}
?>
sorry if my question is not clear,
any help is appreciated
Thank You,