Passing variables

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

Threaded View
I allows users to enter data in a form. I process the form with a php file.  
I return control to another page on my website. I want to dynamical create  
the page that they are returned to so I can show them a copy of what they  
just entered. I cant get the syntax of this. My host is set to globals on  
and php 4.


<FORM method="post" action="process_this.php" name="anmals" id="anmals" >
<TABLE width="400" BORDER="2" CELLSPACING="0" cellpadding="4">
<td >Name</td>
<td ><input type="text" size="45" name="realname" value= ""></td>

Header("Location: index5c.html")

On index5c.html I want to use $realname to display the data the user entered  
on the form. There is something I am missing here as I am getting "null"  
back. I have tried various combinations of commands which I wont go into  
here. Can someone explain how I can pass the user data to index5c.html and  
display it.

Garry Jones

Re: Passing variables

what is the motivation behind using the index5c.html page. Generally
you display your content on the same page you submit to.

Also you cannot use a header() call if anything has already been

In your example $realname is a variable local only to the
process_this.php file. When you call header() you redirect the user to
index5c.html which has no access to the $realname variable.

Re: Passing variables

Quoted text here. Click to load it

Ok, maybe I am not going about this in the best way. Lets start from the  

I have a page in which users can enter data about themselves and their  
friends to sign up for a sporting event. I process the form and the MySQL  
coding with process_this.php. I then return control to the index5c.html  
which thanks the user for his registration(s). Here, I thought would be a  
good idea to remind the user of the data that has been keyed in. Based on  
how many participants the user has registered and according to which  
distance for each participant is signed up for the total price will be  
different. That will all come later first I need to be able to pass  
variables back.

However, a thought struck me. Maybe its best not to process the SQL coding  
straight away. When the user clicks submit maybe I can use a preview page  
which shows the user the data entered and asks him to confirm the  
registration. Here I could also use some maths to show him the ammount of  
money to pay in if he confirms. Cancel would send the user back to the entry  
form, OK would submit and send to a process php file which would handle the  
code for MySQL.

So, starting like this...

<FORM method="post" action="preview_this.php" name="anmals" id="anmals" >
<TABLE width="400" BORDER="2" CELLSPACING="0" cellpadding="4">
<td >Name</td>
<td ><input type="text" size="45" name="realname" value= ""></td>

I need to create a preview page. In this preview I need to show $realname  
and be able to do some calculations on other variables before displaying the  
data. I'd like to show a new form with no user editable information, the  
user reads it, sees the ammount payable and clicks OK or Cancel. OK sends it  
off to the process_this.php

Can someone point me in the right direction to set this up.

Garry Jones

Re: Passing variables

Garry Jones wrote:
Quoted text here. Click to load it
You can use hidden fields or sessions to pass the data.  If data security is a  
concern, I recommend sessions.

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

Re: Passing variables

Quoted text here. Click to load it

I found the readonly tag of the input field. I can now pass variables around  
and set an identical same form to readonly. By php include I should be able  
to turn readonly off or on according to it being the preview form or data  
entry form. I am now testing and it is starting to take shape

Garry Jones

Re: Passing variables

Your problem is that it is process_this.php that has the form post
information, when you do the header request to forward to index5c.html
it's just like loading a fresh page with no post data.

To get around that, i'd use a session.
For example:
on both process_this.php and index5c.html put at the very top:

Now in process_this.php put:
$_SESSION['realname'] = $_POST['realname'];

Then in index5c.html you can directly reference the session variable or
assign it and use it in your html:
Hello <?php echo $_SESSION['realname'] ?>.

Re: Passing variables

i assume you have your web server set up to parse html files in php.
Most servers interpret html as normal files to send flat out to the
browser and php files are interpreted and then sent.

Just be careful about that, otherwise your session wont work and itll
actually display session_start(); to the user.

Re: Passing variables

On Wed, 12 Apr 2006 18:15:21 +0200, Garry Jones wrote...
Quoted text here. Click to load it

Since your FORM ACTION is pointing to process_this.php, that's were you can
capture the values for $_POST. Because you are opening a new HTML document
called "index5c.html" that one will not know what the $_POST or $_GET form
variables are. Since you are passing the form fields to your process_this.php
program, you can use that to create conditions on what HTML document to print.


Newsguy Bandwidth Blowout April-18-2006
Unlimited downloads all day long

Re: Passing variables

Why not post the form to index5c.html?

Does process_this.php do anything else?

Re: Passing variables

Personally I would have all this on one page. There is a lot of
duplication involved.

To do it your way you need to pass variables between pages. There are a
number of ways to do this.

1) Session
2) Get str
3) Cookie.

Session - good for large amount of data, and stored on server.
Get - good for limited amount of data, if the string makes sense by
itself then the page can be bookmarked,
Cookie - I think you may as well use a session but they do occasionally
have their uses.

We also find putting a timestamp on form posts and values to be useful.
What happens if the same user sends a form twice, by going back in the
browser or pressing refresh? Do they get registered twice. Store the
form in the session using the timestamp created in a hidden field in
the form. Check the timestamps as they come in, and the form name
against previous forms to do an array_equals(). If you find you've got
exactly the same thing then you have a duplicate post, if not then you
have to process the form as normal.

Site Timeline