ms1990kl Posted August 20, 2007 Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65744-keeping-data-alive-after-the-submit-button-is-hit/ Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 on the form. add some hidden fields or use sessions were need to see some code Quote Link to comment https://forums.phpfreaks.com/topic/65744-keeping-data-alive-after-the-submit-button-is-hit/#findComment-328416 Share on other sites More sharing options...
ms1990kl Posted August 20, 2007 Author Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65744-keeping-data-alive-after-the-submit-button-is-hit/#findComment-328494 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/65744-keeping-data-alive-after-the-submit-button-is-hit/#findComment-328500 Share on other sites More sharing options...
ms1990kl Posted August 20, 2007 Author Share Posted August 20, 2007 Thanks, That was the help I needed. This is a great website. Mike Quote Link to comment https://forums.phpfreaks.com/topic/65744-keeping-data-alive-after-the-submit-button-is-hit/#findComment-328510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.