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

Link to comment
Share on other sites

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

 

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.