Loan Calculator, Flat Rate Interest Method Using PHP

infoslearning

Flat rate interest, is the type of interest that interest will stay the same on the principal loan amount throughout your loan tenure.

Flat rate interest formula

Total Interest = LoanAmount x (InterestRate/100) x period

Total Payable = Total interest + Loan Amount

In this tutorial, we will use PHP to create a loan calculator by using the flat rate method. The following PHP code is used to find loan payments. You can just copy, and paste this PHP code and use it to find the loan payment.

Create a file called index.php’ and write the following code.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Loan Calculator, Using Flate Rate Method in PHP </title>

	<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
	
</head>
<body>
	<br>
	<br>
<div class="container">
  <h1 align="center">Loan Calculator</h1>
	<form method="POST" action="">
  <div class="form-group" >
    <label for="exampleInputEmail1">Loan Amount</label>
    <input type="number" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="e.g. 100000" name="amount" required="true">
  
  </div>
    <div class="form-group">
    <label for="exampleInputEmail1">Interest (Per Month)</label>
    <input type="number" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="e.g. 1.5" name="interest_rate" step="any" required="true">
   
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Period (Months)</label>
    <input type="number" class="form-control" id="exampleInputPassword1" placeholder="e.g. 12" name="period" required="true">
  </div>

  <button type="submit" name="submit" class="btn btn-primary">Calculate</button>
</form>

<br>

  <table id="example1" class="table table-bordered table-striped">             

  <thead >
<?php
$loan_amount=$interest_rate=$period=NULL;

$total_interest=$total_payable=$monthly_payable=0;

if(isset($_POST['submit'])){

	$loan_amount=$_POST['amount'];

	$interest_rate=$_POST['interest_rate'];

	$period=$_POST['period'];

	

	$total_interest=$loan_amount*($interest_rate/100)*$period;

	$total_payable=$total_interest+$loan_amount;

	$monthly_payable=$total_payable/$period;

}          
  ?>

   

          
                 <tr>                  
                  <th width="40%" class="text-right">Loan Amount</th>
                  <td ><?=number_format($loan_amount, 2);?></td>
                </tr>
                 <tr>                  
                  <th width="40%" class="text-right">Total Interest</th>
                  <td ><?=number_format($total_interest, 2);?> </td>
                </tr>
                  <tr>
                  
                  <th width="40%" class="text-right">Total Loan (Principal + Interest)</th>
                  <td><?=number_format($total_payable, 2);?></td>
                </tr>                 
                   <tr>
                  
                  <th width="40%" class="text-right">Monthly Payment</th>
                  <td><?=number_format($monthly_payable, 2);?></td>
                </tr>

                </thead>

  </table>
  
	</body>
</html>

 

A Reducing Balance Loan is less expensive than a flat-rate loan because interest is calculated on the balance owing rather than the initial amount borrowed. This means the balance owing decreases, and the interest charged each period decreases as well.

You can save money and pay off your loner sooner if you pay back more than the minimum amount each period or make payments more frequently.


Other Recommended for you

  • .Firebase Realtime Database vs Firestore.
  • .What is an Intent in Android? Types of Intent
  • .What is Firebase?
  • .How to Get Number of Remaining Days Between Two Date in PHP