473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I make a var survive page reload?

Mo
I am trying to calculate open-account credibility for new customers.

I have set up a form in which to enter the feedback from their trade
references, but the vars get reset each time the page loads.
The page is terms.php, and I intentionally have it processing itself
because I need the user to be able to repeatedly enter feedback, or
stop at any time, and get results of the compiled avg's regardless.

For example (very simplified): ------------
<form action="terms.php" method="post">
<input type="hidden" name="formCount" value="1">
Terms: Net <input type="text" name="formTerms" size="2" value=""/>
Days
Avg Days to Pay: <input type="text" name="formDaysPaid" size="2"
value=""/>
</form>

if(isset($_POST["formCount"]))
{
$count += $_POST["formCount"];
$terms += $_POST["formTerms"];
$avgDays += $_POST["formDaysPaid"];
}

$score = $terms/$avgDays*100;
$score /= $count;

print "Score: {$score}";
-------------------------------------------

When submitted, I want the score, as well as the form available for
more values. This is why it must post to itself.
When submitted AGAIN, I want the current values $count, $terms, and
$avg to survive the reload, and get the new $_POST values added into
their current values.

IE:
Terms: [ 30 ]
Avg Days to Pay: [ 32 ]
*submit*

Terms: [ 45 ]
Avg Days to Pay: [ 55 ]
*submit*

Terms: [ 15 ]
Avg Days to Pay: [ 30 ]
*submit*

Desired values would now be $count=3, $terms=90, and $avgDays=117.
$score would calculate out at 25.64.

As I have it right now, each time I hit the submit button, $count,
$terms, and $avg get NEW values.

Any Tips?
~ Mo
Oct 2 '08 #1
2 3139
On Oct 3, 12:43*am, Mo <Mehile.Orl...@gmail.comwrote:
I am trying to calculate open-account credibility for new customers.

I have set up a form in which to enter the feedback from their trade
references, but the vars get reset each time the page loads.
The page is terms.php, and I intentionally have it processing itself
because I need the user to be able to repeatedly enter feedback, or
stop at any time, and get results of the compiled avg's regardless.

For example (very simplified): ------------
<form action="terms.php" method="post">
<input type="hidden" name="formCount" value="1">
Terms: Net <input type="text" name="formTerms" size="2" value=""/>
Days
Avg Days to Pay: <input type="text" name="formDaysPaid" size="2"
value=""/>
</form>

if(isset($_POST["formCount"]))
{
$count *+= $_POST["formCount"];
$terms += $_POST["formTerms"];
$avgDays += $_POST["formDaysPaid"];

}

$score = $terms/$avgDays*100;
$score /= $count;

print "Score: {$score}";
-------------------------------------------

When submitted, I want the score, as well as the form available for
more values. This is why it must post to itself.
When submitted AGAIN, I want the current values $count, $terms, and
$avg to survive the reload, and get the new $_POST values added into
their current values.

IE:
Terms: [ 30 ]
Avg Days to Pay: [ 32 ]
*submit*

Terms: [ 45 ]
Avg Days to Pay: [ 55 ]
*submit*

Terms: [ 15 ]
Avg Days to Pay: [ 30 ]
*submit*

Desired values would now be $count=3, $terms=90, and $avgDays=117.
$score would calculate out at 25.64.

As I have it right now, each time I hit the submit button, $count,
$terms, and $avg get NEW values.

Any Tips?
~ Mo
The 4 most common methods in PHP to do this are sessions, cookies,
hidden form fields and query string parameters. Cookies and sessions
are documented in the PHP manual. The hidden form fields involves
creating a hidden form field (duh :) ) and populating it with a
variable you want to preserve. Query strings are similar but you can
also use them in URLs.
Oct 3 '08 #2
Mo
On Oct 3, 3:12*am, Gordon <gordon.mc...@ntlworld.comwrote:
On Oct 3, 12:43*am, Mo <Mehile.Orl...@gmail.comwrote:
I am trying to calculate open-account credibility for new customers.
I have set up a form in which to enter the feedback from their trade
references, but the vars get reset each time the page loads.
The page is terms.php, and I intentionally have it processing itself
because I need the user to be able to repeatedly enter feedback, or
stop at any time, and get results of the compiled avg's regardless.
For example (very simplified): ------------
<form action="terms.php" method="post">
<input type="hidden" name="formCount" value="1">
Terms: Net <input type="text" name="formTerms" size="2" value=""/>
Days
Avg Days to Pay: <input type="text" name="formDaysPaid" size="2"
value=""/>
</form>
if(isset($_POST["formCount"]))
{
$count *+= $_POST["formCount"];
$terms += $_POST["formTerms"];
$avgDays += $_POST["formDaysPaid"];
}
$score = $terms/$avgDays*100;
$score /= $count;
print "Score: {$score}";
-------------------------------------------
When submitted, I want the score, as well as the form available for
more values. This is why it must post to itself.
When submitted AGAIN, I want the current values $count, $terms, and
$avg to survive the reload, and get the new $_POST values added into
their current values.
IE:
Terms: [ 30 ]
Avg Days to Pay: [ 32 ]
*submit*
Terms: [ 45 ]
Avg Days to Pay: [ 55 ]
*submit*
Terms: [ 15 ]
Avg Days to Pay: [ 30 ]
*submit*
Desired values would now be $count=3, $terms=90, and $avgDays=117..
$score would calculate out at 25.64.
As I have it right now, each time I hit the submit button, $count,
$terms, and $avg get NEW values.
Any Tips?
~ Mo

The 4 most common methods in PHP to do this are sessions, cookies,
hidden form fields and query string parameters. *Cookies and sessions
are documented in the PHP manual. *The hidden form fields involves
creating a hidden form field (duh :) ) and populating it with a
variable you want to preserve. *Query strings are similar but you can
also use them in URLs.
Thank you both for the direction.
I now know where to dig.

~ Mo
Oct 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: zdhiu | last post by:
Hi javascript gurus, I have a simple html file (simple.html) with javascript. In html page there is sentence from variable defined in .js file (myFirst.js). Once I reload another .js file...
37
by: ajay | last post by:
How to make a web page getting refreshed after a given time interval automatically. HTML Code plz. Tx Ajay
18
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running...
8
by: Salvatore Sanfilippo | last post by:
Hello all, I've a very simple problem that appears to don't have a simple solution. I've a (dynamically generated) page with a number of external links. What I need is that if the user clicks...
8
by: T. Wintershoven | last post by:
Hi all, Is there a simple way in php to reload a page coded within an if statement.(see code below) It's very important that the session stays intact. The filename is RCStudent.php ...
2
by: Max | last post by:
Is it possible to reload a web page on user browser when an event occurs at server side? For example when user A places an order, user B should be notified of that and should see that order on his...
16
by: sreemati | last post by:
Hi everyone, This is the scenario: I have two button - Submit and Reset Submit is used for validation and after validation is passed it passes it to another form to enter into database. ...
5
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I used the following code to refresh the parent page, and it works very well (Thanks to Peter Bromberg "). Response.Write("<script language='javascript' type='text/javascript'{...
2
by: ericisjusteric | last post by:
I have a page with multiple iframes and need to have the user (ie6) be able to click a button to refresh any one of the iframes - but also to click another button at the top of the page to refresh...
4
by: Mo | last post by:
I am trying to calculate credibility for new customers so they can attain open-account. I have set up a form (on test.php, and processed by the same page) into which feedback from their trade...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.