Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sessions + forms = problem 1

Status
Not open for further replies.

Lexussss

Programmer
Joined
Jul 6, 2004
Messages
1
Location
CA
I have a problem to put any data into session variables via forms. Without forms that works fine.

First page - type username, second page - type password, third page - print username and password.
There is listing:

===============================
page1.php
--------------
<?php
session_start();
print session_id();
?>

<html>
<body>
<form name="form1" method="get" action="page2.php">
<input type="text" name="nameid">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

===================================
page2.php
-------------
<?php
session_start();
$nameid=$_POST['nameid'];
$_SESSION['nameid']=$nameid;
print session_id();
?>

<html>
<body>
<form name="form1" method="get" action="page3.php">
<input type="text" name="passid">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
=======================================
page3.php
--------------
<?php
session_start();
$passid=$_POST['passid'];
$_SESSION['passid']=$passid;

print session_id();
echo $_SESSION['nameid'];
echo $_SESSION['passid'];

session_destroy();
?>
========================================
 
Ok, lets start with some basic error checking.

In page2.php is $nameid actually a value or is it just empty? An 'echo $nameid;' will help

In page3.php what is the outcome of both echo statements? and what is the output of 'echo $passid;' ?

If these do output the expected values what then is the problem? Actually what is the problem full stop?

JR
As a wise man once said: To build the house you need the stone.
Back to the Basics!
 
All of your forms have the attribute 'method="get"'. However, each script is looking for values in $_POST. You either need to change your forms to 'method="post"' or change your scripts to look in $_GET for values.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top