First we will have to originate a new Php file: simplecarloancalculator.php. A Php file is treated by the web server as a general Html file except for the code written inside a php tag.
We start off by creating the car loan calculator Html form submitting data back to this web page.
Car price:
Term:
Interest rate:
The code above will originate a form containing three text boxes and a button.
Car price: ___
Term: ___
Interest rate: ___
[Calculate]
Can be translated to:
When the reason button is pressed the data in the text boxes will be sent to the page named: simplecarloancalculator.php (the page we have all ready have loaded in our web browser). Our current page simplecarloancalculator.php will be reloaded and we will have way to the data entered into the form in an array named $_Post.
To be able to use the data entered into the car price text box we use $_Post[carPrice], where carPrice is the name used in the form above. Since we in reality are using the Php code before the form is created we will place the code above the form.
Php coding
Car Loan Calculator - Php Basic Programming
We will start off with two functions and one variable.
isset() - function to test if variable is set [returns true/false].
empty() - function to test if the variable is empty [returns true/false].
$carPrice - variable to store the car price in.
Looks like isset() and empty() are doing pretty much the same but I will soon justify the slightly but very prominent difference.
Let us seek a code snippet.
if (isset($_Post['carPrice']) && !empty($_Post['carPrice']))
$carPrice = check_input($_Post['carPrice']);
else
$carPrice = 0;
isset($_Post['carPrice']) --> If something was posted in texbox named carPrice (will return true even if an empty box was posted).
empty($_Post['carPrice']) --> If nothing is in $_Post['carPrice'] (will return true first time the page is loaded).
multi vitamins for face do multivitamins work for hair growth
No comments:
Post a Comment