Question: Modify the Future Value Application so it uses a persistent session to save the last values entered by the user for 2 weeks. As your
Modify the Future Value Application so it uses a persistent session to save the last values entered by the user for 2 weeks. As your starting point, you may use the files you already submitted, or you may begin with a fresh project.
Here is the 2 files that I already did some work on in previous assignments. I am looking just to do what is asked above. This is an assignment from cookies and sessions in PHP. Thank you!
index.php
//set default value of variables for initial page load
if (!isset($investment)) { $investment = ''; }
if (!isset($interest_rate)) { $interest_rate = ''; }
if (!isset($years)) { $years = ''; }
?>
>
Future Value Calculator
display_results.php
// get the data from the form
$investment = filter_input(INPUT_POST, 'investment',
FILTER_VALIDATE_FLOAT);
$interest_rate = filter_input(INPUT_POST, 'interest_rate',
FILTER_VALIDATE_FLOAT);
$years = filter_input(INPUT_POST, 'years',
FILTER_VALIDATE_INT);
// validate investment
if ( $investment === NULL || $investment === FALSE ) {
$error_message = 'Investment must be a valid number.'; }
else if ( $investment
$error_message = 'Investment must be greater than zero.'; }
// validate interest rate
else if ( $interest_rate === NULL || $interest_rate === FALSE ) {
$error_message = 'Interest rate must be a valid number.'; }
else if ( $interest_rate
$error_message = 'Interest rate must be greater than zero.'; }
// validate years
else if ( $years === NULL || $years === FALSE ) {
$error_message = 'Number of years must be a valid whole number.'; }
else if ( $years
$error_message = 'Numbr of years must be greater than zero.'; }
// set error message to empty string if no invalid entries
else {
$error_message = ''; }
// if an error message exists, go to the index page
if ($error_message != '') {
include('index.php');
exit();
}
// calculate the future value
$future_value = $investment;
if (isset($_POST["monthly"])) {
//compound monthly
$compounded_monthly="Yes";
$months=$years*12;
$monthly_rate = $interest_rate / 12;
for ($i=1;$i
$future_value =$future_value + ($future_value * $monthly_rate * .01);
}
}
else {
for ($i = 1; $i
$future_value =$future_value + ($future_value * $interest_rate * .01);
}
}
// apply currency and percent formatting
$investment_f = '$'.number_format($investment, 2);
$yearly_rate_f = $interest_rate.'%';
$future_value_f = '$'.number_format($future_value, 2);
$monthly_rate_f=number_format($monthly_rate,2).'%';
?>
Future Value Calculator
if (isset($_POST["monthly"])) {
echo "";
echo "".$monthly_rate_f." ";
echo" ";
echo "".$months." ";
echo" ";
echo"".$future_value_f." ";
echo"Compound Monthly:".$compounded_monthly."";
} else {
echo "";
echo "".$yearly_rate_f." ";
echo" ";
echo "".$years." ";
echo" ";
echo"".$future_value_f." ";
}
?>

Future Value Calculator Investment Amount Yearly Interest Rate: Nurmlpr of Years Future Value: $1,000.00 5% $1,276.28 This calculation was done on 06/19/17
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
