Saturday, January 3, 2015

Car Loan Calculator - Php Basic Programming

Loan Calculator - Car Loan Calculator - Php Basic Programming

First we will have to create a new Php file: simplecarloancalculator.php. A Php file is treated by the web server as a normal 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 create a form containing three text boxes and a button. Car price: ___ Term: ___ Interest rate: ___ [Calculate]
Can be translated to:
When the suspect 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.

Car Loan Calculator - Php Basic Programming

isset() - function to test if changeable is set [returns true/false].
empty() - function to test if the changeable is empty [returns true/false].
$carPrice - changeable to store the car price in.

Looks like isset() and empty() are doing pretty much the same but I will soon by comparison the slightly but very leading difference.
Let us peruse 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).

histats

Best Anti Aging Skin Care 2014

No comments:

Post a Comment