What Will I Learn?
- You will learn to make the calculation of profit and loss PHP
- You will learn to input capital and sell prices
- You will learn to make calculation data
Requirements
- You have basic about PHP
- You have basic about HTML
- You must install XAMPP as a function running php or html by calling localhost in web address
- Text Editor and a Browser
Difficulty
- Basic
Tutorial Contents
- Create one folder in C: /xampp/htdocs/ calculate me here create folder count
- Open your text editor software for this tutorial I am using Notepad ++
- make a simple form just because to enter the amount of capital profit and loss
- create a file with the name index.php and hitung.php then save in the folder C: xampp/htdocs/ count if confused to learn just follow the steps below
index.php
<!DOCTYPE html>
<html>
<head>
<title>Membuat perhitungan laba dann rugi dengan php | www.steemit.com/@tantry</title>
</head>
<body>
<h1>www.steemit.com/@tantry</h1>
<h3>Membuat perhitungan laba rugi dengan PHP</h3>
<br/>
<form method="post" action="hitung.php">
<table>
<tr>
<td>Harga Jual</td>
<td><input type="text" name="harga"></td>
</tr>
<tr>
<td>Modal</td>
<td><input type="text" name="modal"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Hitung!"></td>
</tr>
</table>
</form>
</body>
hitung.php
<?php
$harga = $_POST['harga'];
$modal = $_POST['modal'];
if($harga > $modal){
$laba = $harga-$modal;
echo "Anda Mendapat LABA Sebesar = " . $laba;
}elseif($modal > $harga){
$rugi = $modal-$harga;
echo "Anda Mendapat RUGI Sebesar = " . $rugi;
}else{
echo "Tidak laba tidak rugi";
}
?>
Explanation
I explain a bit in part hitung.php because there are 2 forms that are named harga and laba
<input type="text" name="harga">
<input type="text" name="modal">
because at the time we submit to make it easier to in process at the next stage.
$harga = $_POST['harga'];
$modal = $_POST['modal'];
then we check the laba and rugi, if the price is greater than the capital means we have got a profit, and if the capital is greater than the price means we lose, so that profit bearti price in less with capital, to get the loss amount means capital at less price.
if($harga > $modal){
$laba = $harga-$modal;
echo "Anda Mendapat LABA Sebesar = " . $laba;
}elseif($modal > $harga){
$rugi = $modal-$harga;
echo "Anda Mendapat RUGI Sebesar = " . $rugi;
}else{
echo "Tidak laba tidak rugi";
}
now we try to run the file index.php, how we just type in the address bar browser http://localhost/hitung/index.php
, then we fill the selling price 6000 while the 4000 capital means we profit 2000
and instead we fill the selling price of 9000 while the 10000 capital then we will automatically lose 1000
Curriculum
Posted on Utopian.io - Rewarding Open Source Contributors
Your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]