Jump to content

session variable is not retained when switching pages


Juarez

Recommended Posts

 

 

 

Hi I'm learning PHP sessions variables.

 

I have a HTML form as below. When I submit the form it passes the entered value as a session variable to processform.php page. (see the code below) This works and I can echo out the variable on the page however when I go to a different page and come back to processform.php the variable has been cleared and I get "Undefined index: name.." on the line where the session variable is set. Session variables should be retained when you come back to the page so what am I missing to do this.

I am testing on  local host by the way.

 

 

 

Many thanks

 

 

 

 

 

 


<strong>Test Form</strong>
<form method="post" action="processform.php"><br/><br/>
<input type="text" name="name" value="testValue" /><br/><br/>
<input type="submit" name="submit"/><br/><br/>

</form>

 

 

 

 


<?php
session_start();

include("menu.php"); 
echo "<br />";

$_SESSION['name']=$_POST['name'];

echo $_SESSION['name'];


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.