i am using dreamweaver for my php. how do i get a variable called username from another page and display it to greet the user by name. i can login to the welcome page but getting and error when calling the variable i.e
<?php 开发者_JAVA技巧$_POST['username'] ?>
Error is Undefined index: username
There are more ways to achieve this but probably the easiest is to create a session after the login and store the username in that session. Than, you can echo the username from that session on any page you want (within the session timespan of course).
set:
$_SESSION['username'] = "me";
Get:
echo $_SESSION['username'];
it should be
<?php $_POST['username'] ?>
and to print it out you should do:
<?php echo $_POST['username']; ?>
You should use sessions for saving the user data: http://www.w3schools.com/php/php_sessions.asp
Init the session:
<?php
session_start();
Save variable:
$_SESSION["user"] = "name";
Get variable:
echo $_SESSION["user"];
Its not <?php POST_['username'] ?>
but <?php $_POST['username'] ?>
Plus you can store the variables in cookies and sessions.
http://php.net/manual/en/features.sessions.php
http://php.net/manual/en/features.cookies.php
I'm not sure dreamweaver allows cookies to be set, however.
精彩评论