Sessions in PHP
These are my 2 pages
index.php:-
<?php session_start(); ?>
<html>
<head>
<title>Enter Your Name</title>
</head>
<body>
<form action="hello.php" method="post">
Wat's U'r name : <input type="text" name="name"/>
<br/>
<input type="submit" value="Next"/>
</form>
</body>
</html>
hello.php:-
<?php session_start() ?>
<html>
<head>
<title>Hey <?php echo $name; ?></title>
</head>
<body>
<?php
$_SESSION['name'] = $_POST['name'];
$name = $_SESSION['name'];
if(is
$country = $_SESSION['country'] = $_POST['Countries'];
echo "Hey " . $name . " you are from " . $country ;
else
{
if(!isset($_SESSION['name']))
{
$_SESSION['name'] = $_POST['name'];
$name = $_SESSION['name'];
}
else
{
echo " Hey ". $name . " So you are from ?<br/>";
echo "<form action=\"hello.php\" method=\"post\" /> ";
echo "<select name=\"Countries\"> ";
echo "<option value=\"India\">India</option> ";
echo "<option value=\"USA\">USA</option>";
echo "<input type=\"Submit\" value=\"Next\"/> ";
echo "</select>";
}
}
?>
<br/>
</body>
</html>
What i want to do is to store both name and country in the session array()
then print them out on hello.php as:-
Hello <name> you are from <country>...
I don't know how to do that...
This page is currently not working...
This page is not working...And
22 Minutes
Discussion Span
lionaneesh
Junior Poster
109 posts since Feb 2010
Reputation Points: 6
Solved Threads: 5
Skill Endorsements: 0
fixed up the problem guyz ...
Anybody who have the same problem
see this :-
index.php
<?php session_start(); ?>
<html>
<head>
<title>Enter Your Name</title>
</head>
<body>
<form action="hello.php" method="post">
Wat's U'r name : <input type="text" name="name"/>
<br/>
<input type="submit" value="Next"/>
</form>
</body>
</html>
hello.php
<?php session_start() ?>
<html>
<head>
<title>Hey <?php echo $_SESSION['name']; ?></title>
</head>
<body>
<?php
if(!isset($_SESSION['name']))
{
$_SESSION['name'] = $_POST['name'];
}
if(!isset($_POST['Countries']))
{
echo " Hey ". $_SESSION['name'] . " So you are from ?<br/>";
echo "<form action=\"hello.php\" method=\"post\" /> ";
echo "<select name=\"Countries\"> ";
echo "<option value=\"India\">India</option> ";
echo "<option value=\"Pakistan\">Pakistan</option>";
echo "<input type=\"Submit\" value=\"Next\"/> ";
echo "</select>";
}
else
{
if(isset($_SESSION['Country']))
{
echo "Hey " . $_SESSION['name'] . " you are from " . $_SESSION['Country'];
}
else
{
$_SESSION['Country'] = $_POST['Countries'];
echo "Hey " . $_SESSION['name'] . " you are from " . $_SESSION['Country'];
}
}
?>
<br/>
</body>
</html>
lionaneesh
Junior Poster
109 posts since Feb 2010
Reputation Points: 6
Solved Threads: 5
Skill Endorsements: 0
Question Self-Answered as of 2 Years Ago