I have 4 buttons on a page that each have their own button. When the button is clicked the page does not refresh nor does it open a new page.
When a button is pressed I want to send the ID of that button via Ajax to a php file in the form of a session. Each of the 4 buttons have a different ID (1,2,3,4). If a user clicks one button and then a second button etc, I want to add each of the clicked button Id's into this session.
This is what I have so far:
Jquery:
$(document).ready(function() {
$('a[name=add]').click(function(e) {
session = $(this).attr('id')
$.post('sessions.php', {session:session}
);
});
});
So that simply checks if a button with the name of "add" has been clicked (all 4 of the buttons have that name), and grabs the buttons ID and sends it to sessions.php
PHP:
<?php
session_start();
$_SESSION['ids'] = $_POST['session'];
?>
Simply creates the session.
The problem I am having is that the PHP session is getting the ID of the first button clicked and that is all. If another button is clicked Ajax does post the button ID but the session only keeps the ID of the first button clicked.
How can I add the ID of the next buttons clicked to the session.
Example: If button 1 and 3 are clicked, I need the session to have ID 1 and 3.