<!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>
<?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";
}
?>
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