470,848 Members | 1,216 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Passing variables

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.

Example
Form

<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>
</TABLE>
</FORM>

process_this.php
$realname=$_POST['realname'];
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
Sweden
Apr 12 '06 #1
8 1485
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
output.

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.

Apr 12 '06 #2
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:
session_start();

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:
<html>
Hello <?php echo $_SESSION['realname'] ?>.
</html>

Apr 12 '06 #3
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.

Apr 12 '06 #4
Why not post the form to index5c.html?

Does process_this.php do anything else?

Apr 12 '06 #5
"Areric" <jo**********@gmail.com> skrev i meddelandet
news:11**********************@z34g2000cwc.googlegr oups.com...
what is the motivation behind using the index5c.html page. Generally
you display your content on the same page you submit to.


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

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>
</TABLE>
</FORM>

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
Sweden


Apr 12 '06 #6
Garry Jones wrote:
"Areric" <jo**********@gmail.com> skrev i meddelandet
news:11**********************@z34g2000cwc.googlegr oups.com...
what is the motivation behind using the index5c.html page. Generally
you display your content on the same page you submit to.

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

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>
</TABLE>
</FORM>

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
Sweden


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.
js*******@attglobal.net
==================
Apr 13 '06 #7
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.

Apr 13 '06 #8
"Jerry Stuckle" <js*******@attglobal.net> skrev i meddelandet
news:CJ********************@comcast.com...
You can use hidden fields or sessions to pass the data. If data security
is a concern, I recommend sessions.


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
Sweden


Apr 13 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Amr Mostafa | last post: by
3 posts views Thread by domeceo | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
3 posts views Thread by Lee | last post: by
12 posts views Thread by Andrew Bullock | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.