hii there..

im have created a user login page with php and mysql.
but somehow im having problem when i try to show username information after user login.

i have put this code

<? echo $myusername ; ?>

but it doesnt show the username..

what can be the problem?

thnks in advance..

Recommended Answers

All 7 Replies

does $myusername have a value?

you are using shorttags "<?", does your server allow them?

does $myusername have a value?

you are using shorttags "<?", does your server allow them?

hii thanks for reply..

yeah it allows "<?"

and i actually used this code

<? echo $_SESSION; ?>

but it didnt work too ..
:(

can you post your code? i can't do much more without seeing how you coded it.

can you post your code? i can't do much more without seeing how you coded it.

thnks again...

somehow it worked now..

didint even change anything.. :D

weird..

a variable (such as $myusername ) must be set in the same script for it to have a value, and thus be echo'd to the page. This means the value will be lost if the user refreshes the or follows a link.

The $_SESSION is a special array that will hold it's value for a user until they close their browser. This means when they log in you must set the session variable:

$_SESSION['myusername'] = "humbug"

Only after you have done that can you retrieve the value of the variable like you did with your echo $_SESSION['myusername']; statement.

Hope that clarified things.

hi this is nathen,
i think this is usefull to you some how,
you first start the session on top first page and the page which you want to show your username.In first page its self you should use $_Post=$_SESSION;
and you use $_SESSION in your second page where you want to show that value..

hi this is nathen,
i think this is usefull to you some how,
you first start the session on top first page and the page which you want to show your username.In first page its self you should use $_Post=$_SESSION;
and you use $_SESSION in your second page where you want to show that value..

it would be $_SESSION['myusername'] = $_POST['myusername'] . you switched them around. there also would need to be some sanitation to prevent xss attacks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.