PHP

A “Retirement Saving Calculator”

Today i am again practice GET , POST methods and develop a simple calculator that calculate retirement benefits. You have to input just your present age, age you retire, annual contribution and the return percentage.

<form action="" method="post">
Your age now : <input type="text" name="currentage" />
 
The age you plan to retire : <input type="text" name="retireage" />
 
Annual Contribution : <input type="text" name="contrib" />
 
Annual return : <input type="text" name="anngain" /> %
 
<input type="submit" name="submit" value="calculate" />
 
NEST EGG : <!--?php echo "$total"; ?-->
 
</form>

Here is a simple form and you have to send and receive data with a simple logical operation.

<?php 
if(!isset($_POST['submit']) || $_POST['submit'] !='calculate'){
    $_POST['currentage']="";
    $_POST['retireage']="";
    $_POST['contrib']="";
    $total=0;
    $anngain=7;
}
else{
    $anngain=$_POST['anngain'];
    $years = $_POST['retireage'] - $_POST['currentage'];
    $yearcount=0;
    $total= $_POST['contrib'];
 
    while($yearcount<=$years){
        $total=$total*(1.0+$anngain/100)+$_POST['contrib'];
        $yearcount=$yearcount+1;
    }
}
 
?>

So, Not so difficult. But i have one confusion still… LoL

You can test this simple calculator here

You can find this at php Bible / Chapter – 6

You may also like
How to Receive Single Product Payment Via Paypal

Leave a Reply