469,358 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

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.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. // this starts the session 
  3. session_start(); 
  4.  
  5. // this sets variables in the session 
  6. $_SESSION['username']=$_POST['username']; 
  7.  
  8. ?> 
Code done on loginarea(where the name is to be displayed)..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // this starts the session 
  3. session_start(); 
  4. // echo variable from the session, we set this on our other page 
  5. echo "welcome ".$_SESSION['username']; 
  6.  
  7. ?> 
Mar 9 '10 #1
6 3658
wizardry
201 100+
you can use it by starting the session on the next page and assigning it to a variable. i.e.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $username = .$_SESSION['username'];
  4.  
  5. echo $username;
  6. ?>
  7.  
Mar 9 '10 #2
hey its still not working n thnx 4 help....
Mar 9 '10 #3
Atli
5,058 Expert 4TB
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?

@wizardry
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.
Mar 9 '10 #4
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
Mar 9 '10 #5
Atli
5,058 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if(isset($_SESSION['c'])) {
  4.     $_SESSION['c'] ++;
  5. }
  6. else {
  7.     $_SESSION['c'] = 1;
  8. }
  9. echo $_SESSION['c'];
  10. ?>
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?)
Mar 9 '10 #6
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.
Mar 9 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by abprules | last post: by
2 posts views Thread by Mark Roughton | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.