• Latest
  • Trending
  • All
  • News

Car Loan Calculator – Php Basic Programming

June 17, 2017
5 Vital Car Cleaning Tools To Make A Car Look Brand New

How Exterior Detailing Services Can Enhance the Look of Your Vehicle

January 21, 2024

The Ultimate Guide to Rebuilding a Transmission – Everything You Need to Know

December 10, 2023
5 Weekend Travel Tips for Lasting Joy With the Family

Preparing Your RV For Storage – Essential Steps to Take

November 21, 2023

5 Reasons Why Regular Auto Repair Services Are Crucial for Your Vehicle

November 21, 2023
Comparing the Services of Open Vs. Enclosed Car Shipping

Comparing the Services of Open Vs. Enclosed Car Shipping

November 20, 2023
Heavy Vs. Light Duty Towing: Knowing The Kind of Truck You’ll Need

Heavy Vs. Light Duty Towing: Knowing The Kind of Truck You’ll Need

November 11, 2023
6 great reasons why vehicle owners won’t be stranded when calling out a local locksmith

6 great reasons why vehicle owners won’t be stranded when calling out a local locksmith

October 27, 2023
Six Reasons to Buy a Classic Corvette

Six Reasons to Buy a Classic Corvette

October 20, 2023
Top 5 Signs of Alternator Problems

Top 5 Signs of Alternator Problems

October 10, 2023
7 Common Engine Rebuilding Mistakes and How to Avoid Them

The Benefits of Reliable Auto Repair Services You Can Trust

October 9, 2023
Practical Car Interior Gadgets to Upgrade Your Ride

Top Reasons Why Used Cars Are a Better Investment

July 2, 2023

Essentials of Handicap Vehicles

June 20, 2023
  • Guest Posts
  • Advertise
  • Contact
  • Privacy Policy
Friday, June 20, 2025
  • Login
Tech Featured - Automotive
  • Home
  • Gadgets
  • Automotive News
  • Interesting Topics
No Result
View All Result
Tech Featured - Automotive
No Result
View All Result
Home News

Car Loan Calculator – Php Basic Programming

June 17, 2017
in News
0
77
SHARES
220
VIEWS
Share on FacebookShare on Twitter

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 calculate 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 access 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

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’]);

}

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).

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.

echo($monthlyCost)

Tags: LoanPhpProgramming
Share31Tweet19Share8
  • Trending
  • Comments
  • Latest

John Christie Electric Generator – Generates 24 Kilowatts Of Free Electricity

November 21, 2016

How to Use a Magnetic Generator to Get Rid of Your Electricity Bill

November 21, 2016

Buying a Gazebo – How to Install a Gazebo on Grass

June 8, 2017

The Environmental Benefits of Automobile Recycling

0

Automotive Fasteners – A Number of Items Included on the List

0

Drag Racing – The Perfect Launch

0
5 Vital Car Cleaning Tools To Make A Car Look Brand New

How Exterior Detailing Services Can Enhance the Look of Your Vehicle

January 21, 2024

The Ultimate Guide to Rebuilding a Transmission – Everything You Need to Know

December 10, 2023
5 Weekend Travel Tips for Lasting Joy With the Family

Preparing Your RV For Storage – Essential Steps to Take

November 21, 2023
Tech Featured - Automotive

Navigate Site

  • Guest Posts
  • Advertise
  • Contact
  • Privacy Policy

Follow Us

No Result
View All Result
  • Home
  • Gadgets
  • Automotive News
  • Interesting Topics

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In