We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,787 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

1
Contributor
1
Reply
22 Minutes
Discussion Span
2 Years Ago
Last Updated
2
Views
Question
Answered
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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1707 seconds using 2.69MB