<?php /* Here\'s a good place to use the null coalescing operator to test the $i
ID: 3730305 • Letter: #
Question
<?php
/* Here's a good place to use the null coalescing operator
to test the $investment, $interest_rate, $years
to see if they have any values, and set to null otherwise.
This is because this page will be loaded the very first time
when these variables have never been used before (no values yet),
as well as when there have been errors detected and the page
is reloaded. No way of knowing unless you test the variables.
What kind of test? If you attempt to assign $investment to $investment (yup, you read that correctly--assign it to itself!), and if it's not set, assign it a NULL. Then, it won't be considered "undefined" when you attempt to print it later in the form. But, interestingly, if the user doesn't enter anything for it, and you attempt to post $investment to the next page (display_results.php), it will be considered an empty string and will pass that test next time. Whew!
*/
?>
<!DOCTYPE html >
<html >
<head>
<title>Future Value Calculator</title>
<!-- (this is an html comment...)
I have included the following css file in the application folder
The most important thing that it does is to display your error
message in red.
-->
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<meta charset="UTF-8">
<body>
<div id="content">
<h1>Future Value Calculator</h1>
<!-- (this is an html comment...)
Display (echo) an error message here, if there is one
$error_message should be set in the display_results.php file
that is where you will validate the input
IMPORTANT NOTE: If there is no error message, then this must be the
first time that you are displaying the form. And the first time that you are
displaying the form, those php variables have not yet been defined (they
are defined in the displayResults page). But you will want to display the php variables in the form itself (or at least, it's a good suggestion for you to do so). So you don't want to get an undefined variable error. Therefore, if you did not use the null coalescing operators at the top of the page, you should set the variables $investment, $interest_rate, and $year to "" (empty strings) in the "else part of the "if $error_message" statement. But it's really better to use the null coalescing operators for this situation. Then, you can just display the php variable for investment, interest and years righ in the form (in php tags), with no further testing.
-->
<!--
create a form. It should look like the picture in the assignment called
"The First Page"
Upon clicking "Calculate", the action should go to display_results.php
You should use POST (not GET) to send the variables to display_results.php
I left a bare-bones form to get you started...
-->
<!--
HINT: Think ahead! The "values" that you want to display in the text boxes
can (and really should) be the PHP variables, instead of just blank boxes. You don't really need that for the first time that the form is displayed. But later, if there is an error in display_results.php, you will want to "include" this page so that the user can re-enter the values. So those variables that were already entered
will be displayed. Rather than create one blank form that displays blank
text boxes, and then an identical form that displays text boxes with
PHP variables displayed, just use PHP variables all of the time.
-->
<form >
<div id="data">
</div>
<div id="buttons">
</div>
</form>
</div>
</body>
</html>
Explanation / Answer
home.php
============================================================================
index.php
=============================================================================
results.php
==========================================================================
main.css
======================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.