By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

How can I make a var survive page reload?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.