Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN php .... I need Help I Need to Modify this application so it uses a persistent session to save the last values entered by

  • IN php ....
  • I need Help I Need to Modify this application so it uses a persistent session to save the last values entered by the user for 5 minutes.
  • At the top of the file (before the DOCTYPE html line) you will need to add a section of code which checks to see if a session id exists. If it does not, the code you add (which will be similar to the example on page 359) will need to start a session.
    • After the above code (and before the DOCTYPE html line) you will need to add a section of code which checks to see if any of the (3) inputs (amount, rate, & years) already exist in $_SESSION[ ]. If they do, you will need to set the initial values for the form fields to those values.
  • In display_results.php:
    • At the top of the file you will need to make sure you start the session (see page 358).
    • After the input field values (amount, rate, & years) are error checked, you will need to store the values in the session (see pp. 360-361)
    • Remember to display the day/time when your calculation was performed.

My code for the original assignment before its modified to a persistent session.

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

Future Value Calculator

Investment Amount: value="

">

Yearly Interest Rate: value="">

Number of Years: value="">

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 === FALSE ) { $error_message = 'Investment must be a valid number.'; } else if ( $investment <= 0 ) { $error_message = 'Investment must be greater than zero.'; // validate interest rate } else if ( $interest_rate === FALSE ) { $error_message = 'Interest rate must be a valid number.'; } else if ( $interest_rate <= 0 ) { $error_message = 'Interest rate must be greater than zero.'; // validate years } else if ( $years === FALSE ) { $error_message = 'Years must be a valid whole number.'; } else if ( $years <= 0 ) { $error_message = 'Years must be greater than zero.'; } else if ( $years > 30 ) { $error_message = 'Years must be less than 31.'; // 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; for ($i = 1; $i <= $years; $i++) { $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); ?>

Future Value Calculator

Future Value Calculator

Investment Amount:

Yearly Interest Rate:

Number of Years:

Future Value:

This calculation was done on echo "" . date("m/d/Y") . " "; ?> at date_default_timezone_set("America/New_York"); echo " " . date("h:i:sa"); ?>.

main.css-->

body { font-family: Arial, Helvetica, sans-serif; } main { display: block; width: 450px; margin: 0 auto; padding: 1em; background: white; border: 2px solid navy; } h1 { margin-top: 0; color: navy; } label { width: 10em; float: left; padding-right: 1em; padding-bottom: .5em; } #data input { float: left; width: 15em; margin-bottom: .5em; } #buttons input { float: left; margin-bottom: .5em; } br { clear: left; } .error { color: red; font-weight: bold; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Outline demographic considerations.

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago

Question

What were your most important educational experiences?

Answered: 1 week ago

Question

How was your life influenced by those events?

Answered: 1 week ago