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

  php

Q(Question):

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

Code done on login form.

<?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)..

<?php
// this starts the session
session_start();
// echo variable from the session, we set this on our other page
echo "welcome ".$_SESSION['username'];
?>

A(Answer):

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


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

A(Answer):

hey its still not working n thnx 4 help….

A(Answer):

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.

A(Answer):

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

A(Answer):

In that case, there are really only two reasons why this is happening.Your $_POST data isn’t getting through correctly. If you print $_POST[‘username’]; in the login page, does it print correctly? 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:

<?php
session_start();
if(isset($_SESSION['c'])) {
$_SESSION['c'] ++;
}
else {
$_SESSION['c'] = 1;
}
echo $_SESSION['c'];
?>

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?)

A(Answer):

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.

LEAVE A COMMENT