Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:06:20+00:00 2026-06-17T11:06:20+00:00

I have 4 buttons on a page that each have their own button. When

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:06:21+00:00Added an answer on June 17, 2026 at 11:06 am
    session_start();
    
    // prepare $_SESSION['ids']
    if ( ! is_array($_SESSION['ids']))
    {
        $_SESSION['ids'] = array();
    }
    
    // fill $_SESSION['ids'] only with new $_POST['session'] posted
    if ( ! in_array($_POST['session'], $_SESSION['ids']))
    {
        $_SESSION['ids'][] = $_POST['session'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have buttons on a page that look like: <p> <a href=view.php> <input type=button
I have 4 buttons on a page. Each button opens a modal window and
I have three menus. Personal Info Mobile Info Documents each buttons have their own
I have a few buttons on my page that are styles using sprites, in
i have a page that contains several submit buttons however i only want one
I have a button on an aspx page that is supposed to send an
I have an aspx page that contains a checkbox, and a button. The button
I have a form in an HTM page that, after pressing the submit button,
I have a page with some user selectable options and a button that, when
I have an asp.net page. There is a button Edit on the bottom that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.