Retaining previous posted values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Retaining previous posted values

Post by jarow »

I have a form that if submitted correctly posts back to itself with a message that says the record was entered correctly.

what I would like to do is retain the last values entered in some of the fields so that they don't have to retype everything if they want to add addtional records (it's a list of species and many times phylum, class, order do not change.)

i thought I could do it with session variables but it doesn't work.

Basically here is an example

Code: Select all

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


Then I put the session variable in the field like this

Code: Select all

<?php echo $HTTP_SESSION_VARS['phylum']; ?>


But all the previously posted values are cleared when it reposts to itself.

What am I doing wrong.

Thanks
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

ok, let me ask a couple things first:

1) Why do you use $_SESSION[] in one place, then $HTTP_SESSION_VARS[] in another? just use $_SESSION if you're coding for PHP 4.2+.

2) Now that we're using $_SESSION exclusively, have you called session_start() at the very beginning (before any HTML is outputted) of every file that accesses the $_SESSION array?
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Post by jarow »

I changed the globals so that they now all read $_SESSION[] and they still do not post.

session_start() is at the beginning of the page before any html.

don't understand why it is clearing the posted values
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

Post by jarow »

Here is the recap if you or anyone has any other ideas.

I am trying to post a form (method = POST) onto itself and retain some of the values the user just entered.

I have called the following before any html

Code: Select all

<?php session_start();
header("Cache-control: private");
$_SESSION['var']=$_POST['var'];?>

I have also created hidden fields for each of the fields I want to use with the following value

Code: Select all

<?php echo $_POST['var'];?>

I have placed this value as a form variable in each of the form fields in which I want to display the previously posted values


I am posting the form to itself

add.php?success=true

(success=true is a Show/IF if the form is entered correctly)

Don´t understand why it´s not working.

Jim
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please post more of your form-code.
If you check your server's error log (or decrease log/display-level) are there undefined index messages?
If you open the requested document in your browser's sourceview, is there something that looks like those values (even if only remote) ?
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Does anybody see something bad in do'ing:

Code: Select all

if(isset($_POST))
  $_SESSION = $_POST;
Post Reply