i'd created a login page, where user need to enter their username and password here, stored in

$username = $_POST["name"];
$password = $_POST["password"];

then after submit button being pressed, the username will show in welcome.php, which is the action for the submit button. From here, the user will have a link to another page with forms, here i need to display the username again. However it cant. How to make the variables pass across pages without using any database?

session variable

use session_start(); at the beginning of the page. store the username and password infomration in $_SESSION and $_SESSION and then just echo them on the other page using echo $_SESSION;

i declared like this:

<?php
session_start();
$_SESSION['name'];
$_SESSION['password'];
$_SESSION['status'];
?>

and calling i8t out using this:

<h2>You are currently logged in as <?php echo  $_SESSION['name'];?></h2>

however still in vain..any syntax errors there?

make sure you have session_start() at the top of the second page to access session variables from another page.

ya..i do have session_start () in both pages:

in the index page:

<?php
session_start();
$_SESSION['name'];
$_SESSION['password'];
$_SESSION['status'];
?>
<html>
<head>
<title>ISO CLAIM PAGE</title>
<link rel="stylesheet" type="text/css" href="my.css">
</head>
<body>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<h1>Please log in using valid username and password</h1>
<form method="post" action="welcome.php" >
............

and in the welcome.php:

<?php
session_start();
$_SESSION['name'];
$_SESSION['password'];
$_SESSION['status'];
?>
<html>
<head>
<title>::. ISO CLAIM PAGE</title>
<link rel="stylesheet" type="text/css"
href="my.css">
</head>
<body>
<br><br><br><br><br><br><br><br><br><br>
<h1>You have successfully log-in!!</h1>
<h1>Welcome to the control panel page. You can either updating your databases or go ahead for your claim.</h1><hr size=2 width=500px>
<h2>You are currently logged in as <?php echo  $_SESSION['name'];?></h2>

oh sorry, i guess i didn't look at your example close enough. the $_SESSION variable is just an array so you have set the name key as something on the login page.

so do you mean like this?

<?php
session_start();
$username = $_SESSION['name'];
$password = $_SESSION['password'];
$status = $_SESSION['status'];
?>

other way, the $_SESSION variable has to set in the login page using $_SESSION = $username; and on the second page you just have to echo it.

if you need a better example let me know and i will type one up for you.

well, i juz need to pass variables and show it in another page...
before tht i ady success pass the variable to the 2nd page..however it cant pass to the 3rd page..do u hav simpler code for it without using database?

so do you mean like this?

<?php
session_start();
$username = $_SESSION['name'];
$password = $_SESSION['password'];
$status = $_SESSION['status'];
?>

yup.. and just echo the variable.. <h2>hi <?php echo $username;?></h2>
this will do..

well, the prob still exist..i try to upload my welcome.php for references....

my index.html codes shown below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?php
session_start();
$username=$_SESSION['name'];
$password=$_SESSION['password'];
$status=$_SESSION['status'];
?>
<html>
<head>
<title>ISO CLAIM PAGE</title>
<link rel="stylesheet" type="text/css" href="my.css">
</head>
<body>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<h1>Please log in using valid username and password</h1>
<form method="post" action="welcome.php" >
<p><label for="name">Username:</label> <input type="text" name="name"></p>
<p><label for="password">Password:</label> <input type="password" name="password"></p>
<p><label> Status:</label><select>
<option>Admin</option>
<option>Staff</option>
</select></p><br>
<h1>Not yet a registered user? Please 
<a href="registration.html">
register </a> here</h1>
<label><input type="submit" value="Submit"></label>
</form>
</body>
</html>

Thats because $_SESSION, $_SESSION , $_SESSION might be empty. Where are you assigning the values for these session variables ? And Its always better to have .php extension to your scripts. :)

well, the variables are assigned within the form:

<form method="post" action="welcome.php" >
<p><label for="name">Username:</label> <input type="text" name="name"></p>
<p><label for="password">Password:</label> <input type="password" name="password"></p>
<p><label> Status:</label><select>
<option>Admin</option>
<option>Staff</option>
</select></p><br>

does it make sense? and i already changed the extension to .php ...

Hi,
as somebody else told you before, you session variables could be empty.
try something like this:

session_start();
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
$_SESSION["status"] = $status

well, the variables are assigned within the form:

<form method="post" action="welcome.php" >
<p><label for="name">Username:</label> <input type="text" name="name"></p>
<p><label for="password">Password:</label> <input type="password" name="password"></p>
<p><label> Status:</label><select>
<option>Admin</option>
<option>Staff</option>
</select></p><br>

does it make sense? and i already changed the extension to .php ...

You aren't assigning these values to the session variables on submit. ie.,
$_SESSION=$_POST;
... and so on..

got it...yeah!!! thanks nav33n and silviuks...

well, after settled that things, now i came across for the upload things. My upload.php as shown below:

<?php
$uploaddir = 'C:\Documents and Settings\evan\Desktop\ALL pHP\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>

i tried to upload the files but unsuccessfully... this upload.php file i uploaded to a php-enabled web hosting and after clicking the upload button a HTML, this page is not found at all.

that path looks like one on your own computer. unless you are using your own server on that computer you can't do that. you have to use a relative path on the server. also make sure you have

enctype="multipart/form-data"

in the starting form tag

that path looks like one on your own computer. unless you are using your own server on that computer you can't do that. you have to use a relative path on the server. also make sure you have

enctype="multipart/form-data"

in the starting form tag

yaya..i already modified the path that store the files. And i do have the enctype at my HTML

<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" >
<h1>Choose a file to upload:</h1>
<div><label><input name="uploadedfile" type="file" ><input type="submit" value="Upload File" ></label>
</div></form>

however it indicates that my upload.php not found. Then i directly clicked that page, it shows:

Upload failed

Here is some more debugging info:Array
(
)

if it is the server side error, cn u suggest a directories easy for me to debug my code? thanks

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.