Compound savings calculator help

I want to create something similar to http://www.bankrate.com/calculators/savings/simple-savings-calculator.aspx

My droplist isn’t effecting anything and i need it to. How do i do that?

[php]?php
if (isset($_POST[‘investment’])) {
$inv = $_POST[‘investment’];
$int = $_POST[‘interest’]/100;
$yrs = $_POST[‘years’];
$compound = $_POST[‘compound’];
};

$interestearned = $inv*(pow(1+$int,$yrs)-1);

$message = “Please enter details as required!”;
if ($inv=="") { echo $message; }
elseif ($int=="") { echo $message; }
elseif ($yrs=="") { echo $message; }
else {

if(isset($_POST[‘compound’])) {

if($compound == 1){
$monthlyi;
}elseif($compound == 2){
$quarterlyi;
}elseif($compound == 3){
$semii;
}elseif($compound == 4){
$yearlyi;
};

$monthlyi = $interestearned/$yrs/12;
$yearlyi = $interestearned/$yrs;
$semii = $interestearned/$yrs/2;
$quarterlyi = $interestearned/$yrs/4;
};
};

?>[/php]

what droplist? where is your form?

[php]

Savings Calculator
 
Initial Amount: $
Interest :     %
Monthly Deposit: $ $10 $20 $30 $40 $50
Number of Years:
 

<?php echo "Investment= $".$inv." | Interest = ".$int*(100)."% | Years = ".$yrs."yrs"; ?>

Interest over <?php echo $yrs; ?> years Amount
Daily $<?php echo number_format($dailyi, 2) ?>
Weekly $<?php echo number_format($weeklyi, 2) ?>
Monthly $<?php echo number_format($monthlyi, 2) ?>
Yearly $<?php echo number_format($yearlyi, 2) ?>
   
Total Interest (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned, 2) ?>
Total (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned + $inv, 2) ?>
[/php]

ok now i’m confused. in your form html you call an empty action, which would work if the two pieces of code are on the same page, but it doesn’t look like that. are these two different files? what are their names?

That is the wrong php code, oops. Here is the full code

[php]<?php
if (isset($_POST[‘investment’])) {
$inv = $_POST[‘investment’];
$int = $_POST[‘interest’]/100;
$yrs = $_POST[‘years’];

$message = “Please enter details as required!”;
if ($inv=="") { echo $message; }
elseif ($int=="") { echo $message; }
elseif ($yrs=="") { echo $message; }
else {

$interestearned = $inv*(pow(1+$int,$yrs)-1);
$dailyi = $interestearned/$yrs/365;
$weeklyi = $interestearned/$yrs/52;
$monthlyi = $interestearned/$yrs/12;
$yearlyi = $interestearned/$yrs;
};
};

if(isset($_POST[‘monthly’])) {

$dep = $_POST[‘monthly’];

if($dep == 1){
$interestearned + (10 *($yrs *12));
}elseif($dep == 2){
$interestearned + (20 *($yrs *12));
}elseif($dep == 3){
$interestearned + (30 *($yrs *12));
}elseif($dep == 4){
$interestearned + (40 *($yrs *12));
}elseif($dep == 5){
$interestearned + (50 *($yrs *12));
};
};

?>
<!doctype html>

Savings Calculator body { background-image: url(images/Savings_Deposit_Program.jpg); } .input { text-align: left; font-size: 24px; }
Savings Calculator
 
Initial Amount: $
Interest :     %
Monthly Deposit: $ $10 $20 $30 $40 $50
Number of Years:
 

<?php echo "Investment= $".$inv." | Interest = ".$int*(100)."% | Years = ".$yrs."yrs"; ?>

Interest over <?php echo $yrs; ?> years Amount
Daily $<?php echo number_format($dailyi, 2) ?>
Weekly $<?php echo number_format($weeklyi, 2) ?>
Monthly $<?php echo number_format($monthlyi, 2) ?>
Yearly $<?php echo number_format($yearlyi, 2) ?>
   
Total Interest (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned, 2) ?>
Total (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned + $inv, 2) ?>
[/php]

ok well there are some things i’d change, like your error checking is really very lackluster. for example, after your form you look for the $_POSTed info, but what if you haven’t filled the form out yet? errors! I duplicated your if isset so that it would not process the unneeded code. better yet, you could make it check for the individual results before trying to echo their table row, etc. i did a fast copy paste:
[php]<?php if (isset($_POST['investment'])) { ?>[/php]
that being said, what do you WANT to happen with the monthly? you accept it as a form element but do nothing with it in your math. what should the math be on this?

MY assumption? you want to multiply the monthly deposit by 12, and then the number of years, and then you want to add it to the initial deposit before doing all of the math on it.

so here:
[php]<?php
if (isset($_POST[‘investment’])) {
$inv = ($_POST[‘investment’] + (($_POST[‘monthly’] * 12) * $_POST[‘years’]));
$int = $_POST[‘interest’]/100;
$yrs = $_POST[‘years’];

$message = "Please enter details as required!";
if ($inv=="") { echo $message; }
elseif ($int=="") { echo $message; }
elseif ($yrs=="") { echo $message; }
else {


    $interestearned = $inv*(pow(1+$int,$yrs)-1);
    $dailyi = $interestearned/$yrs/365;
    $weeklyi = $interestearned/$yrs/52;
    $monthlyi = $interestearned/$yrs/12;
    $yearlyi = $interestearned/$yrs;
};

};

if(isset($_POST[‘monthly’])) {

$dep = $_POST['monthly'];

if($dep == 1){
    $interestearned + (10 *($yrs *12));
}elseif($dep == 2){
    $interestearned + (20 *($yrs *12));
}elseif($dep == 3){
    $interestearned + (30 *($yrs *12));
}elseif($dep == 4){
    $interestearned + (40 *($yrs *12));
}elseif($dep == 5){
    $interestearned + (50 *($yrs *12));
};

};

?>
<!doctype html>

Savings Calculator body { background-image: url('images/Savings_Deposit_Program.jpg'); } .input { text-align: left; font-size: 24px; }
Savings Calculator
 
Initial Amount: $
Interest :     %
Monthly Deposit: $ $10 $20 $30 $40 $50
Number of Years:
 
<?php if (isset($_POST['investment'])) { ?>

<?php echo "Investment= $".$inv." | Interest = ".$int*(100)."% | Years = ".$yrs."yrs"; ?>

Interest over <?php echo $yrs; ?> years Amount
Daily $<?php echo number_format($dailyi, 2) ?>
Weekly $<?php echo number_format($weeklyi, 2) ?>
Monthly $<?php echo number_format($monthlyi, 2) ?>
Yearly $<?php echo number_format($yearlyi, 2) ?>
   
Total Interest (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned, 2) ?>
Total (after <?php echo $yrs; ?> years) $<?php echo number_format($interestearned + $inv, 2) ?>
<?php } ?> [/php]

good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service