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.
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 explain the slightly but very important difference.
Let us examine a code snippet.
If (isset($_POST['carPrice']) && !empty($_POST['carPrice']))
$carPrice = check_input($_POST['carPrice']);
$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).
Combined together the expressions (please notice the ! Before empty function) will be evaluated as:
If something was typed in the text box named carPrice and the box was not empty. Variable $carPrice
will be set to that something, otherwise set variable $carPrice to 0.
The same procedure will needed for term and interestRate as well, creating variables $term and $interestRate, but that code will not be repeated here.
Time to do the mathematical work.
We will next create a function taking the three input parameters $totalLoan, $years and $interest. The function will then return the cost per month rounded off to whole dollars.
Function calculateMonthlyAmortizingCost($totalLoan, $years, $interest )
$tmp = pow((1 + ($interest / 1200)), ($years * 12));
return round(($totalLoan * $tmp) * ($interest / 1200) / ($tmp – 1));
Next step will be using our newly created function and passing our variables as arguments.
$monthlyCost = calculateMonthlyAmortizingCost($carPrice, $term, $interestRate);
And we are done! Almost, we need to print the price on the web page. To do that we will use the echo function that outputs text to the web page.
To see an example of this calculator visit [http://www.loaningforcar.com/simplecarloancalculator.php] where the full car loan calculator source code will be presented. Hermes Andersson [http://www.loaningforcar.com]
Latest in food-track tech: Swipe a code, meet your fisherman – KSL.com
KSL.comLatest in food-track tech: Swipe a code, meet your fishermanKSL.comPORTLAND, Maine (AP) — After eyeing a piece of haddock on the supermarket counter, a customer scans a code and finds out the fish was caught in the waters of Georges Bank and learns the name of the fishing boat — and maybe even sees a picture of the …and more »