take the user name entered in text box to another form??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mansi579
    New Member
    • Mar 2010
    • 3

    take the user name entered in text box to another form??

    How to i move information posted in one form to another?

    Code done on login form.
    Code:
    <?php 
    // this starts the session 
    session_start(); 
    
    // this sets variables in the session 
    $_SESSION['username']=$_POST['username']; 
    
    ?>
    Code done on loginarea(where the name is to be displayed)..
    Code:
    <?php
    // this starts the session 
    session_start(); 
    // echo variable from the session, we set this on our other page 
    echo "welcome ".$_SESSION['username']; 
    
    ?>
    Last edited by Atli; Mar 9 '10, 05:42 AM. Reason: Added [code] tags.
  • wizardry
    New Member
    • Jan 2009
    • 201

    #2
    you can use it by starting the session on the next page and assigning it to a variable. i.e.

    Code:
    <?php
    session_start();
    $username = .$_SESSION['username'];
    
    echo $username;
    ?>

    Comment

    • mansi579
      New Member
      • Mar 2010
      • 3

      #3
      hii

      hey its still not working n thnx 4 help....

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hey.

        How exactly is it not working?
        Is it printing nothing?
        Or is it printing something else?

        Are you getting any errors?
        Do you have the error messages turned on?

        Is there anything else going on that might help us determine what is really going on?

        Originally posted by wizardry
        you can use it by starting the session on the next page and assigning it to a variable. i.e.
        Assigning it to a variable is purely optional. The $_SESSION super-global can be used just as any normal array can be used. - However, it is usually a good idea to extract and validate data from external sources (sessions, post, get, cookies, databases, etc...) before using them.

        Comment

        • mansi579
          New Member
          • Mar 2010
          • 3

          #5
          hii..its jsut printing nothing...

          no errors no warnnings nothing it just prints nothing means
          its like this ...
          welcome
          n if i write like this ...
          $_SESSION['username']="mansi"..
          then it prints
          welcome mansi

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            In that case, there are really only two reasons why this is happening.
            1. Your $_POST data isn't getting through correctly. If you print $_POST['username']; in the login page, does it print correctly?
            2. The session cookie is not working properly. In this case, it would either be a problem with your browser or your server config.


            Try this. Create a new PHP page and put this code in it:
            [code=php]<?php
            session_start() ;
            if(isset($_SESS ION['c'])) {
            $_SESSION['c'] ++;
            }
            else {
            $_SESSION['c'] = 1;
            }
            echo $_SESSION['c'];
            ?>[/code]
            Then open the page in your browser and hit refresh (F5) a bunch of times. The number should increase each time. - If it doesn't there is most likely a problem with your server. (Unless your browser is configured to not accept session cookies?)

            Comment

            • philipwayne
              New Member
              • Mar 2010
              • 50

              #7
              If its a next-page deal( forms are in a sequence ) you could just use GET rather then POST assuming you don't need to carry over allot of information also its a "bad idea" to put passwords in GET.

              Also make sure your submitting the forms using method POST.

              Comment

              Working...