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'];


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.