View Full Version : regarding auto posting

04-26-2004, 05:36 AM
my problem is this?

I have two textboxes in which i enter the values of A and B in the php page(first page).
I should create another php page which will take these values, add them up in the second page and post the result in a third page automatically.
Is there a way I could implement that .



04-26-2004, 08:32 AM
Of course.:

First page:

<form action="page1.php" method="post">
Text1: <input type="text" name="textbox2"/>
Text2: <input type="text" name="textbox2"/>
<input type="submit" value="Go!"/>

Second page:


if( (!isset( $_POST['textbox2'] )) && (!isset( $_POST['textbox2'] )) ) {
die("You did not enter all required values, <a href=\"pageone.htm\">click here</a> to try again!");

$result = $_POST['textbox1']+$_POST['textbox2'];

// store them, or send them.

Now third page will depend on how the second page is written, are you going to store the value in a cookie or session, or database hashed by cookie or session or do you want it sent as a querystring etc.. there are a number of possibilities but that is essentially what you need, of course assuming I read your post correctly.

04-26-2004, 02:12 PM
thanks for replying to the post and giving your idea.
I am not using a query string. I may use a database or sessions for the third page. Querystrings are not secure. Actually on the third page, i would like to display The result of A and B is C.
how could i do that.

04-26-2004, 02:41 PM
What is your actual question or where do you need info on?

- compute the value from the posted formfields?
- store the resulting value in a sessionvariable?
- print the value form the sessionvariable on the third page?

As an aside: you're just computing something with values the client entered himself and the resulting value that you pass along in the QS is printed on screen anyway, so i don't see the securityissue here.

04-26-2004, 04:18 PM
Using the query string, the result will appear on the browser as http://address.php?result=somevalue. I dont want the result to appear on the URL but be displayed in a different php page

here is the code i worked on till now
this is my first page where i pass the values.
if (isset($_POST['submit'])) {

print("<form method = POST action = 'research.php'>");

$termCount= 2;
print ("<table>");
for ($n=0; $n < $termCount; $n++)
print ("<tr>");
print ("<td>");
$text = "'TextBox".$n."'";
$termTextField = $text;
print ("<INPUT TYPE='text' NAME=$termTextField VALUE='' cols='' size=''>");
print ("</td>");
print ("</tr>");
print ("</table>");

print ("<input type='submit' name='submit' value='Search'>");
print ("</form>");
else {
// display form
<form method="post" action="<?php echo $PHP_SELF?>">
<?php # <input type="text" name = "Text1"> ?>
<input type="Submit" name="submit" value="Click Here to Search">


this is my second page from where i am trying to repost the result back to the first page or any other third page. Here i am using query strings to view the result. Is there a way of doing that without querystrings and using sessions or hidden variables?

<title>Search Processing</title>
$count = 0;
foreach ($_POST as $key=>$value)
$count = $count + $value;
Header("Location: repost.php?count=$count");

04-26-2004, 07:00 PM
On your second page, store the posted variable inside a sessionvariable like

session_start(); // on top of your page
$_SESSION['test'] = $_POST['test'];

Then on other pages, you get the value like

session_start(); // on top of your page
$myvariable = $_SESSION['test'];

04-26-2004, 08:52 PM
Just to let you know however, that a querystring will not be used with a "POST" form.... only GET forms will make a querystring, so you could use post....