I'm new to using PHP sessions and I'm having trouble updating a session array using the form $_POST method.
Basically, each button has a value that I want to add to the array $_SESSION['items']
on each click. However, currently what is happening is the array gets reset and replaced by the last selected value.
Here's what I've got so far:
<?
session_name("test");
session_start();
?>
<form method="post">
<button type="submit" name="item[]" value="Item 1">Item 1</button>
<button type="submit" name="item[]" value="Item 2">Item 2</button>
</form>
<?
$_SESSION['items'] = array();
array_push($_SESSION['items'], $_POST['item']);
print_r($_SESSION['items']);
?>
Any help would be appreciated.
Thanks!