ExpertAlmost Posted November 23, 2008 Share Posted November 23, 2008 Good morning! My understanding is that the only way to gather user input in php is to use GET/POST in HTML. This can then call a php code page to process the user input. (I do not want to have 5 php files worth of processing in my one HTML file and just using include/require does NOT get me from the bottom of my HTML script back to the top to run again.) However I output the data (ob_start or not) I need to get back to my original HTML page, (or another HTML file is fine) from within my php page so as to gather data again from the user...then back to the php to process...until the user stops clicking on buttons. In other words: 1) Open HTML page in browser with some FORM buttons. User clicks a button. 2) Form button opens a php program which registers which button was clicked. 3) PHP program does many things, including generating $FinalNumber 4) $FinalNumber's value must be saved for the next iteration of the php program (after going back to HTLM and returning to PHP). 4) Go back to step one and repeat as often as user clicks buttons... Steps 1-3 I can do. Steps 4 and 5 I do not know how to do. In general, what is the best way to go back to an HTML script/file from a PHP file? How to save a PHP variable while going between PHP-HTML-PHP iterations? I am new at this and struggling with it. Thank you so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/ Share on other sites More sharing options...
redarrow Posted November 23, 2008 Share Posted November 23, 2008 php sessions........ test.php <?php session_start(); // must be on all pages use the session... $_SESSION['final_number']="123456789"; ?> echo_session.php <?php session_start();//must be on all pages that use the session... echo $_SESSION['final_number']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/#findComment-696866 Share on other sites More sharing options...
Daniel0 Posted November 23, 2008 Share Posted November 23, 2008 http://www.phpfreaks.com/tutorial/sessions-and-cookies-adding-state-to-a-stateless-protocol Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/#findComment-696869 Share on other sites More sharing options...
ExpertAlmost Posted November 23, 2008 Author Share Posted November 23, 2008 That's fantastic! Always helps to know a group of geniuses I've been studying about sessions and it looks like a perfect solution to Step 4 (below), saving my $FinalNumber. But how do I go from my php file BACK to the original HTML file to reiterate the entire process? Step 5 to Step 1? In other words: 1) Open HTML page in browser with some FORM buttons. User clicks a button. 2) Form button opens a php program which registers which button was clicked. 3) PHP program does many things, including generating $FinalNumber 4) $FinalNumber's value must be saved for the next iteration of the php program (after going back to HTLM and returning to PHP). 5) Go back to step one and repeat as often as user clicks buttons... Better informed but still slightly boggled... Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/#findComment-696977 Share on other sites More sharing options...
Daniel0 Posted November 23, 2008 Share Posted November 23, 2008 You could store the numbers in an array: form.php <form action="process.php" method="post"> <label for="number">Enter number:</label> <input type="text" name="number" id="number"> <button type="submit">Send</button> </form> process.php <?php session_start(); $number = intval($_POST['number']); // do stuff to number and get $finalNumber if (!isset($_SESSION['finalNumbers'])) { $_SESSION['finalNumbers'] = array(); } $_SESSION['finalNumbers'][] = $finalNumber; echo 'Your final numbers: ' . join(', ', $_SESSION['finalNumber']); echo '<br><a href="form.php">Back to form</a>'; ?> Not tested, by the way. Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/#findComment-696979 Share on other sites More sharing options...
ExpertAlmost Posted November 24, 2008 Author Share Posted November 24, 2008 A heartfelt thanks to everyone contributing to this thread! For super green new newbies like myself, the mentoring provided by those of you in the know really makes learning this stuff more efficient, less painful and certainly melts the Antarctic isolation of learning alone. Good karma all around ExpertAlmost (thanks to you!) Quote Link to comment https://forums.phpfreaks.com/topic/133870-how-to-move-from-php-file-back-to-html-script/#findComment-697435 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.