Jump to content

keeping data alive after the submit button is hit


ms1990kl

Recommended Posts

I have a website where the user inputs some data, hits the submit button, and some results are returned.

I want the results to stay on the page when the user hits the submit button again.

In other words, when the user hits the submit button the first time he gets this:

 

Hit 1:  results of hit 1.

 

When he inputs some data and hits the input button a second time, the screen looks like this:

 

Hit 1:  results of hit1

Hit 2:  results of hit2

 

An so on.

 

The user will then be asked which results he wants to use for a final sort of averaging.

 

Where can I find some information on how to do this sort of thing.  I have not been able to figure out how to keep from losing all my information when the submit button is hit.  

 

I suspect this is sort of basic stuff, but I am just learning.

 

Thanks so much for your time.

Mike

Thanks,

I read about sessions and tried the following code:

<?php

session_register("counter");

session_register("answer");

 

$_SESSION['counter']=$_SESSION['counter']+1;

$count=$_SESSION['counter'];

 

if(array_key_exists('dataGetter', $_GET))

$_SESSION['answer["$count"]']=$_GET['data'];

else $_SESSION['answer["$count"]'] = "";

 

echo $count-1;

echo $_SESSION['answer["$count"]'];

?>

 

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">

<input name="data" type="text"  size="2" maxlength="5" />  <br/><br/>

<input type="submit" name="dataGetter" id="dataGetter" value="Submit Data"/>

</form>

 

I think that after 5 inputs I have stored five values in the session array 'answer', but

when I replace the last line with the following lines I get undefined index error.

echo $_SESSION['answer[1]'];

echo $_SESSION['answer[2]'];

echo $_SESSION['answer[3]'];

echo $_SESSION['answer[4]'];

echo $_SESSION['answer[5]'];

 

Can you help?

Mike

 

to handle arrays

do this

$_SESSION['answer'][$count] = "";

echo $_SESSION['answer'][$count]

 

think of $_SESSION['answer'] as you would $answer

 

common problems with SESSION are due to the fact their headers see this post

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.