pause processing

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
A php script processes some form inputs to produce an array of data for
further processing before insertion into a database table. I'd like to
give the user an opportunity to examine the print_r() of that array
before continuing.

The idea I had in the php script was something like:

// ... build the $what array

function process($what) {
  // further process the $what array
  // and insert into the table

echo "<form action=\"process()\" method=\"post\">\n";
  echo "<input type=\"hidden\" name=\"what\" value=\"what\">";
echo "<input type=\"Submit\" value=\"Insert into Transactions\">\n";
echo "<pre>$date<br><br>$what = "; print_r($what);


but of course that fails as the process() function is unknown to the web

How might I accomplish allowing the user the chance to examine the array
before proceeding please? I suppose I could declare $what as a global
variable and have the form invoke another php script that processes it,
but strongly suspect that there're better ways of doing it.

Thank you.

Re: pause processing

Greg Russell wrote:
Quoted text here. Click to load it

You won't be able to do it in the same script; the script will end
before everything gets sent to the user.

What you will need to do is save the data somewhere and display it for
the user (in a form).  When the user submits the form, store the data in
the database.

If the data's not too big, you can store it in the $_SESSION array.  But
if it is large, you should find another way to store it, i.e. a
temporary table in the database (and have some way to clear the data if
it isn't submitted).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: pause processing

Jerry Stuckle wrote:
Quoted text here. Click to load it

He could use the same script - just have separate sections and some
method for keeping track of where he is in the process. Maybe a session
variable or hidden field that is passed along.


if variable-pass1 is not set
then display the form
else variable1-pass1
elseif variable2

Just a bit more elegant:

switch ($x)
case 1:
   echo "Number 1";
case 2:
   echo "Number 2";
case 3:
   echo "Number 3";
   echo "No number between 1 and 3";


and of course the third option:

form.php -> verify.php -> process.php

If you use the temp db table to store the data as it is process (again
depending on how much data), at the process.php move it from temptable
to permtable. If you use this method, don't forget to to have a
timestamp column so you know when they executed up to the verify and
decided not to process the transaction.  You will now have "orphaned"
data in the temp table - or you can store it for n-days and allow them
to pick up where they left off (most places just make you re-enter the
entire transaction). That is a design decision you will need to make.

Site Timeline