Jump to content

Recommended Posts

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!

 

 

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'];

?>

 

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...

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.

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!)

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.