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 9044113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:54:15+00:00 2026-06-16T10:54:15+00:00

hello i have problem with the following code that is on the head of

  • 0

hello i have problem with the following code that is on the head of every page:

session_start();

if (!isset($_SESSION['a'])){
    ...create the session from some variables...
$_SESSION['a'] = $var;
$var = $_SESSION['a'];
}else{
    $var = $_SESSION['a'];
    $what = "some text";

    if (isset($_POST['one']) ){
        $var = "new input";
            $_SESSION['a'] = $var;
        echo "one was posted";
    }
    if (isset($_POST['two']) ){
            $var = "new input";
            $_SESSION['a'] = $var;
        echo "two was posted";
    }   
}

the form to post is placed in the footer:

<form action="'.$_SERVER['PHP_SELF'].'" method="post">      
    <input type="submit" id="one" name="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">  
    <input type="submit" id="two" name="two"/><div>set two</div>
</form>

something seems to be wrong in the logic behind the code above. when calling the page, and sending post issue, it will not echo and not change the session to the new value.

so if there is someone who could help me out i really would appreciate.

thanks alot.

UPDATE:

okay, the code works completely up to the “else” part:

else{
    $var = $_SESSION['a'];

    if (isset($_POST["one"]) ){
        echo "post one was send";
    }
    if (isset($_POST["two"]) ){
        echo "post en was send";
    }

echo "session already exists.";
}

this part only shows the echo: session already exists. the whole post phrase does not work.
the footer will be embedded depending from some variables. so the whole content in html will be echoed:

echo '...
      <ul class="drop_down">
    <form action="'.$_SERVER['PHP_SELF'].'" method="post">      
        <input type="submit" id="one" name="one value="one"/><div>set one</div>
    </form>
    <form action="'.$_SERVER['PHP_SELF'].'" method="post">  
        <input type="submit" id="two" name="two" value="two"><div>set two</div>
    </form>
      </ul>
     ...';
  • 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-16T10:54:16+00:00Added an answer on June 16, 2026 at 10:54 am

    Change Your Form

       <form action="<?=$_SERVER['PHP_SELF']?>" method="post">      
       <input type="submit" id="one" name="one" value="one"/><div>set one</div>
       </form>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">  
       <input type="submit" id="two" name="two" value="two"/><div>set two</div>
    </form>
    

    value Need to be sent..


    Edit#1:


    In my system this is working fine..

            <?php
            session_start();
    
            if (!isset($_SESSION['a'])){
               $var='hi';
            $_SESSION['a'] = $var;
            $var = $_SESSION['a'];
            }else{
                $var = $_SESSION['a'];
                $what = "some text";
    
                if (isset($_POST['one']) ){
                    $var = "new input";
                        $_SESSION['a'] = $var;
                    echo "one was posted";
                }
                if (isset($_POST['two']) ){
                        $var = "new input";
                        $_SESSION['a'] = $var;
                    echo "two was posted";
                }   
            }
            ?>
            <form action="<?=$_SERVER['PHP_SELF']?>" method="post">      
                <input type="submit" id="one" name="one"/><div>set one</div>
            </form>
            <form action="<?=$_SERVER['PHP_SELF']?>" method="post">  
                <input type="submit" id="two" name="two"/><div>set two</div>
            </form>
    

    Edit#2


    Try this again…

            if (!isset($_SESSION['a'])){
               $var='hi';
            $_SESSION['a'] = $var;
            $var = $_SESSION['a'];
            }else{
                $var = $_SESSION['a'];
                $what = "some text";
    
                if (isset($_POST['one']) ){
                    $var = "new input1";
                        $_SESSION['a'] = $var;
                    echo "one was posted";
                    print_r($_SESSION);
                }
                if (isset($_POST['two']) ){
                        $var = "new input2";
                        $_SESSION['a'] = $var;
                    echo "two was posted";
                    print_r($_SESSION);
                }   
            }
            ?>
            <form action="<?=$_SERVER['PHP_SELF']?>" method="post">      
                <input type="submit" id="one" name="one"/><div>set one</div>
            </form>
            <form action="<?=$_SERVER['PHP_SELF']?>" method="post">  
                <input type="submit" id="two" name="two"/><div>set two</div>
            </form>
    

    Here session is printing correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a problem with the following code in a GTMTestCase: - (void)testSomething
Hello i'm practising C and i have a little problem with the following code.
The Problem I have the following code: <html> <head> <style id=ID_Style> .myStyle { color
Hi I have problem in code that the following code retuning the error that
I have a problem with the MASM32 assembler The following code is a Hello
hello i have the following problem: i would like to create a filter for
Hello every body I have used following code in my jpa project for working
Hello i have the following problem, I record a video using red5 like this:
I have a problem in the following code: //quesry the db for image information
Hello all I have this problem that I can't seem to fix. I've been

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.