0

Contoh Sederhana pemograman PHP

Posted by jujur on 3:44 PM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Harga BBM</title>
</head>

<body>
<div align="center"><br/>Tabel Harga BBM</div><br/><br/>
<form id="form1" name="form1" method="post" action="bbm.php">
<table width="450" border="1" align="center">
<tr>
<td width="100" align="center"> Liter Awal </td>
<td width="100" align="center"> Liter Akhir </td>
<td width="100" align="center"> Bensin</td>
<td width="100" align="center"> Solar </td>
<td width="100" align="center"> Minyak Tanah </td>
<table width="450" border="1" align="center">
<td width="80" align="center">
<select name="literawal" id="literawal">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select></td>
<td width="80" align="center">
<select name="literakhir" id="literakhir">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select></td>
<td width="80" align="center">
<input type="checkbox" name="cbensin" value="bensin"><br/>
</td>
<td width="80" align="center">
<input type="checkbox" name="csolar" value="Solar"><br/>
</td>
<td width="80" align="center">
<input type="checkbox" name="cmtanah" value="Minyak Tanah"><br/>

</td>
<table width="450" border="1" align="center">
<td width="80" align="center">
<center><input type="submit" name="submit" value="submit" /><br/></center>
</tr>

</table>
<?php
$literawal = $_POST[literawal];
$literakhir = $POST[literakhir];
$cbensin=$_POST[cbensin];
$csolar=$_POST[csolar];
$cmtanah=$_POST[cmtanah];
$bensin = "";
$solar="";
$minyaktanah="";
if($literawal=="1")
{
$bensin="6000";
$solar="5500";
$minyaktanah="2500";
}
else
if($literawal=="2")
{
$bensin="12000";
$solar="11000";
$minyaktanah="5000";
}
else
if($literawal=="3")
{
$bensin="18000";
$solar="16500";
$minyaktanah="7500";
}
else
if($literawal=="4")
{
$bensin="24000";
$solar="22000";
$minyaktanah="10000";
}else
if($literawal=="5")
{
$bensin="30000";
$solar="27500";
$minyaktanah="12500";
}else
if($literawal=="6")
{
$bensin="36000";
$solar="33000";
$minyaktanah="15000";
}else
if($literawal=="7")
{
$bensin="42000";
$solar="38500";
$minyaktanah="17500";
}else
if($literawal=="8")
{
$bensin="48000";
$solar="44000";
$minyaktanah="20000";
}else
if($literawal=="9")
{
$bensin="54000";
$solar="49500";
$minyaktanah="22500";
}else
if($literawal=="10")
{
$bensin="60000";
$solar="55000";
$minyaktanah="25000";
}else
if($literawal=="11")
{
$bensin="66000";
$solar="60500";
$minyaktanah="27500";
}else
if($literawal=="12")
{
$bensin="72000";
$solar="66000";
$minyaktanah="30000";
}else
if($literawal=="13")
{
$bensin="78000";
$solar="71500";
$minyaktanah="32500";
}else
if($literawal=="14")
{
$bensin="84000";
$solar="77000";
$minyaktanah="35000";
}else
if($literawal=="15")
{
$bensin="90000";
$solar="82500";
$minyaktanah="37500";
}else
if($literawal=="16")
{
$bensin="96000";
$solar="88000";
$minyaktanah="40000";
}else
if($literawal=="17")
{
$bensin="102000";
$solar="93500";
$minyaktanah="45000";
}else
if($literawal=="18")
{
$bensin="108000";
$solar="98000";
$minyaktanah="47500";
}else
if($literawal=="19")
{
$bensin="114000";
$solar="103500";
$minyaktanah="47500";
}else
if($literawal=="20")
{
$bensin="120000";
$solar="109000";
$minyaktanah="50000";
}else
if($literawal == "0");
{
$ket_literawal =$literawal;
}
if (isset($_POST['cbensin']))
{
$sbensin = $bensin;

}
if (isset($_POST['csolar']))
{
$ssolar = $solar;
}
if (isset($_POST['cmtanah']))
{
$sminyaktanah = $minyaktanah;
}
$literakhir = $literakhir - $literawal;


?>



<center>
<table width="450" border="1">

<tr>
<td width="109" align="center">Liter</td>
<td width="109" align="center">Bensin</td>
<td width="109" align="center">Minyak Tanah</td>
<td width="109" align="center">Solar</td>
</tr>
<tr>
<td width="175"><?php echo $ket_literawal;?></td>
<td width="175"><?php echo $sbensin;?></td>
<td width="175"><?php echo $sminyaktanah;?></td>
<td width="175"><?php echo $ssolar;?></td>
</tr>
<p>&nbsp;</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Harga BBM</title>
</head>

<body>
<div align="center"><br/>Tabel Harga BBM</div><br/><br/>
<form id="form1" name="form1" method="post" action="bbm.php">
<table width="450" border="1" align="center">
<tr>
<td width="100" align="center"> Liter Awal </td>
<td width="100" align="center"> Liter Akhir </td>
<td width="100" align="center"> Bensin</td>
<td width="100" align="center"> Solar </td>
<td width="100" align="center"> Minyak Tanah </td>
<table width="450" border="1" align="center">
<td width="80" align="center">
<select name="literawal" id="literawal">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select></td>
<td width="80" align="center">
<select name="literakhir" id="literakhir">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
</select></td>
<td width="80" align="center">
<input type="checkbox" name="cbensin" value="bensin"><br/>
</td>
<td width="80" align="center">
<input type="checkbox" name="csolar" value="Solar"><br/>
</td>
<td width="80" align="center">
<input type="checkbox" name="cmtanah" value="Minyak Tanah"><br/>

</td>
<table width="450" border="1" align="center">
<td width="80" align="center">
<center><input type="submit" name="Tampilkan" value="Tampilkan" /><br/></center>
</tr>

</table>
<?php
$literawal = $_POST[literawal];
$literakhir = $POST[literakhir];
$cbensin=$_POST[cbensin];
$csolar=$_POST[csolar];
$cmtanah=$_POST[cmtanah];
$bensin = "";
$solar="";
$minyaktanah="";
if($literawal=="1")
{
$bensin="6000";
$solar="5500";
$minyaktanah="2500";
}
else
if($literawal=="2")
{
$bensin="12000";
$solar="11000";
$minyaktanah="5000";
}
else
if($literawal=="3")
{
$bensin="18000";
$solar="16500";
$minyaktanah="7500";
}
else
if($literawal=="4")
{
$bensin="24000";
$solar="22000";
$minyaktanah="10000";
}else
if($literawal=="5")
{
$bensin="30000";
$solar="27500";
$minyaktanah="12500";
}else
if($literawal=="6")
{
$bensin="36000";
$solar="33000";
$minyaktanah="15000";
}else
if($literawal=="7")
{
$bensin="42000";
$solar="38500";
$minyaktanah="17500";
}else
if($literawal=="8")
{
$bensin="48000";
$solar="44000";
$minyaktanah="20000";
}else
if($literawal=="9")
{
$bensin="54000";
$solar="49500";
$minyaktanah="22500";
}else
if($literawal=="10")
{
$bensin="60000";
$solar="55000";
$minyaktanah="25000";
}else
if($literawal=="11")
{
$bensin="66000";
$solar="60500";
$minyaktanah="27500";
}else
if($literawal=="12")
{
$bensin="72000";
$solar="66000";
$minyaktanah="30000";
}else
if($literawal=="13")
{
$bensin="78000";
$solar="71500";
$minyaktanah="32500";
}else
if($literawal=="14")
{
$bensin="84000";
$solar="77000";
$minyaktanah="35000";
}else
if($literawal=="15")
{
$bensin="90000";
$solar="82500";
$minyaktanah="37500";
}else
if($literawal=="16")
{
$bensin="96000";
$solar="88000";
$minyaktanah="40000";
}else
if($literawal=="17")
{
$bensin="102000";
$solar="93500";
$minyaktanah="45000";
}else
if($literawal=="18")
{
$bensin="108000";
$solar="98000";
$minyaktanah="47500";
}else
if($literawal=="19")
{
$bensin="114000";
$solar="103500";
$minyaktanah="47500";
}else
if($literawal=="20")
{
$bensin="120000";
$solar="109000";
$minyaktanah="50000";
}else
if($literawal == "0");
{
$ket_literawal =$literawal;
}
if (isset($_POST['cbensin']))
{
$sbensin = $bensin;

}
if (isset($_POST['csolar']))
{
$ssolar = $solar;
}
if (isset($_POST['cmtanah']))
{
$sminyaktanah = $minyaktanah;
}



?>



<center>
<table width="450" border="1">

<tr>
<td width="109" align="center">Liter</td>
<td width="109" align="center">Bensin</td>
<td width="109" align="center">Minyak Tanah</td>
<td width="109" align="center">Solar</td>
</tr>
<tr>
<td width="175"><?php echo $ket_literawal;?></td>
<td width="175"><?php echo $sbensin;?></td>
<td width="175"><?php echo $sminyaktanah;?></td>
<td width="175"><?php echo $ssolar;?></td>
</tr>
<p>&nbsp;</p>
</body>
</html>




<html>
<head>
<title>Hitung Harga BBM</title>
</head>
<body>
<div align="center">

<?php
$liter_awal = 0;
$liter_akhir = 0;

if(isset($_POST['liter_awal']))
$liter_awal = $_POST['liter_awal'];

if(isset($_POST['liter_awal']))
$liter_akhir = $_POST['liter_akhir'];

?>

<form name="harga" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<h2>DAFTAR HARGA BBM</h2>
<table border="1" width="350">
<tr>
<td>Liter Awal</td>
<td>Liter Akhir</td>
<td>Bensin</td>
<td>Solar</td>
<td>Minyak Tanah</td>
</tr>

<tr>
<td>
<select name="liter_awal">
<?php
for($i = 1; $i <= 20; $i++){
if($i == $liter_awal)
echo '<option value="'.$i.'" selected>'.$i.'</option>';
else
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
</td>
<td>
<select name="liter_akhir">
<?php
for($i = 1; $i <= 20; $i++){
if($i == $liter_akhir)
echo '<option value="'.$i.'" selected>'.$i.'</option>';
else
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
</td>
<td align="center">
<input type="checkbox" name="bensin" value="bensin" <?php if(isset($_POST['bensin']))echo 'checked'?>>
</td>
<td align="center">
<input type="checkbox" name="solar" value="solar" <?php if(isset($_POST['solar']))echo 'checked'?>>
</td>
<td align="center">
<input type="checkbox" name="minyak_tanah" value="minyak_tanah" <?php if(isset($_POST['minyak_tanah']))echo 'checked'?>>
</td>
</tr>
<tr>
<td align="center" colspan="5"><input type="submit" name="tampil" value="Tampilkan"></td>
</tr>
</table>
</form>
<?php
$harga_bensin = 6000;
$harga_solar = 5500;
$harga_minyak = 2500;
?>
<table border="1">
<?php
if(!isset($_POST['tampil'])){
?>
<tr>
<td width="20" align="center">Liter</td>
<td width="90" align="center">Bensin</td>
<td width="90" align="center">Solar</td>
<td width="90" align="center">Minyak Tanah</td>
</tr>
<?php
for($i = 1;$i <= 10; $i++){
?>
<tr>
<td align="right"><?php echo $i;?></td>
<td align="right"><?php echo number_format($harga_bensin*$i, 0, '', '.');?></td>
<td align="right"><?php echo number_format($harga_solar*$i, 0, '', '.');?></td>
<td align="right"><?php echo number_format($harga_minyak*$i, 0, '', '.');?></td>
</tr>
<?php
}
} else {
if($liter_awal > $liter_akhir){
$temp = $liter_akhir;
$liter_akhir = $liter_awal;
$liter_awal = $temp;
}

$bensin = "";
$solar = "";
$minyak = "";

echo '<td align="center" width="20">Liter</td>';
if(isset($_POST['bensin']))
echo '<td align="center" width="90">Bensin</td>';
if(isset($_POST['solar']))
echo '<td align="center" width="90">Solar</td>';
if(isset($_POST['minyak_tanah']))
echo '<td align="center" width="90">Minyak Tanah</td>';

for($i = $liter_awal;$i <= $liter_akhir; $i++){
?>
<tr>
<td align="right"><?php echo $i;?></td>
<?php if(isset($_POST['bensin'])){ ?>
<td align="right"><?php echo number_format($harga_bensin*$i, 0, '', '.');?></td>
<?php } if(isset($_POST['solar'])){ ?>
<td align="right"><?php echo number_format($harga_solar*$i, 0, '', '.');?></td>
<?php } if(isset($_POST['minyak_tanah'])){ ?>
<td align="right"><?php echo number_format($harga_minyak*$i, 0, '', '.');?></td>
<?php }?>
</tr>
<?php
}
}
?>
</table>
</div>
</body>
</html>






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Validasi Form</title>
<meta name="author" content="Jujur Soaloon Sitanggang">
<?php error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
?>
</head>
<body>
<center>


                        <h3>1. Regular Expression Sederhana</h3>
                        <h5> Masukan Huruf A - Z </h5>
    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="str" value="<?php echo $_POST[str] ?>">
                <input type="submit" value="Proses">
            </form>
                                                <?php
                                                $string = $_POST[str];
                                                if(preg_match("/fgh/", $string)) {
                                                                        echo 'String berisi pola fgh';
                                                }
                                                else {
                                                                        echo 'Tidak ada pola fgh dalam string';
                                                }
                                                ?>



<h3>2. Meta Character </h3>
<h5>Masukan angka perkalian </h5>
   <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="mcr" value="<?php echo $_POST[mcr] ?>">
                <input type="submit" value="Proses">
            </form>
                                               
                                                                        <?php
                                                $string = $_POST[mcr];
                                               
                                                if(preg_match("/^10\+10/i", $string)) {
                                                                        echo 'String : ';
                                                                        echo $string;
                                                                        echo 'Pola 10+10 ditemukan';
                                                }
                                                else {
                                                                        echo 'String : ';
                                                                        echo $string;
                                                                        echo 'Pola 10+10 tidak ditemukan';
                                                }
                                                ?>

                        <br>

<h4> 3. Masukan Email</h4>
                        <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="eml" value="<?php echo $_POST[eml] ?>">
                <input type="submit" value="Proses">
            </form>

                                                <?php
                        $email= $_POST[eml];
                        if(preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email))
                        {
                        //echo '<td> email :';
                        //echo $email;
                        echo 'Email valid';
                        }
                        else {
                        //echo 'email :';
                        //echo $email;
                        echo 'Email tidak valid';
                        }
                                                ?>
<br>

<h4> 4. Masukan no telp area Bandung(022) </h4>

                                                  <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="kkw" value="<?php echo $_POST[kkw] ?>">
                <input type="submit" value="Proses">
            </form>

                                                <?php
                                                $telp =$_POST[kkw];
                                               
       
        if(preg_match("/022-?[0-9]{8}$/", $telp)) {
            //echo 'Telp : ';
                                                                        //echo $telp;
                                                                        echo 'Nomer telp Bandung';
        }
        else {
           // echo 'Telp : ';
                                                                        //echo $telp;
                                                                        echo 'Nomer telp bukan area Bandung';
        }
        ?>

<br>
<h4> 5. Masukan Huruf </h4>
        <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="dpn" value="<?php echo $_POST[dpn] ?>">
                <input type="submit" value="Proses">
            </form>

                        <?php
                            $string = $_POST[dpn];
                       
                                                if(preg_match("/unikom(?=bandung)/", $string))
                                                {
                                                //echo '$string : ';
                                                //echo $string;
                                                echo 'Pattern ditemukan';
                                                }
                                                else {
                                                //echo '</td> $string :';
                                                //echo $string;
                                                echo 'Pattern tidak ditemukan';
                                                }
                                                ?>
</br>


<h4> 6. Masukan Huruf Sembarang "Case Sensitive" </h4>
                                                <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                                                                        <input type="text" name="csn" value="<?php echo $_POST[csn] ?>">
                <input type="submit" value="Proses">
            </form>

                                                <?php
                                               
                                               
                                                $string = $_POST[csn];
                                                if(preg_match("/^ABC/i", $string))
                                                {
                                                echo 'String : ';
                                                echo $string;
                                                echo 'String berawalan abc';
                                                }
                                                else {
                                                echo 'String : ';
                                                echo string;
                                                echo 'Tidak berawalan abc'; }
                                                ?>
</body>
</html>
<html>
<head>
<title> Perhitungan Tabungan </title>
</head>

<body>
<div align = "center"><br/><font size="5"> Perhitungan Tabungan </div><br/><br/>
<?php
if(isset($_POST['hitung'])){
$saldo_awal = 0;
$bunga = 0;
$jangka_waktu = 0;
$hasil_bunga = 0;
$saldo = 0;
$saldo_awal = $_POST['saldo_awal'];
$bunga = $_POST['bunga']/100;
$jangka_waktu = $_POST['jangka_waktu'];
}
?>
<form id = "form1" name = "form1" method = "post" action = "2_perhitungan_tabungan.php">
<table width = "500" border = "1" align = "center">
<tr>
<td align="center"> Saldo Awal </td>
<td align="right"><input type="text" size="11" name="saldo_awal" value = "<?php if(isset($_POST['hitung'])) echo $saldo_awal; ?>"></td>
</tr>
<tr>
<td align="center"> Bunga (%) </td>
<td align="right"><input type="text" size="11" name="bunga" value = "<?php if(isset($_POST['hitung'])) echo $bunga*100; ?>"></td>
</tr>
<tr>
<td align="center"> Jangka Waktu </td>
<td align="right"><input type="text" size="11" name="jangka_waktu" value = "<?php if(isset($_POST['hitung'])) echo $jangka_waktu; ?>"></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Hitung" name="hitung">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>

<?php
if(isset($_POST['hitung'])){
?>
<center> Detail Tabungan </center>
<table border = "1" width = "500" align = "center">
<tr>
<td align="center"> Bulan </td>
<td align="center"> Saldo </td>
<?php
$saldo = $saldo_awal;
for($i=1; $i<=$jangka_waktu; $i++){
$hasil_bunga = $bunga*$saldo;
$saldo = $saldo +$hasil_bunga;
?>
<tr>
<td><?php echo $i; ?></td>
<td align = "right">Rp. <?php echo number_format($saldo,0,",","."); ?></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>




<html>
<head>
<title>Hitung Biaya Kost</title>
</head>
<body>
<div align="center" style="margin-top: 30px">
<?php
$tipe = "";
$air = "";
$telepon = "";
$televisi = "";
$komputer = "";
$rice_cooker = "";
$biaya_kamar = 0;
$biaya_air = 0;
$biaya_telepon = 0;
$biaya_televisi = 0;
$biaya_komputer = 0;
$biaya_rice_cooker = 0;
$total = 0;

if(isset($_POST['tipe']))
$tipe = $_POST['tipe'];

if(isset($_POST['air']))
$air = $_POST['air'];

if(isset($_POST['telepon']))
$telepon = $_POST['telepon'];

if(isset($_POST['televisi']))
$televisi = $_POST['televisi'];

if(isset($_POST['komputer']))
$komputer = $_POST['komputer'];

if(isset($_POST['rice_cooker']))
$rice_cooker = $_POST['rice_cooker'];

?>
<form name="harga" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<table border="3" width="250">
<tr>
<th colspan="2"> PERHITUNGAN HARGA KOST</th>
</tr>
<tr>
<td width="100">Tipe Kamar</td>
<td width="150">
<select name="tipe">
<option value="A" <?php if($tipe == "A") echo 'selected'?>>A (2 x 3 m)</option>
<option value="B" <?php if($tipe == "B") echo 'selected'?>>B (3 x 3 m)</option>
<option value="C" <?php if($tipe == "C") echo 'selected'?>>C (4 x 3 m)</option>
</select>
</td>
</tr>
<tr>
<td>Air</td>
<td>
<input type="radio" name="air" value="Air PDAM" <?php if($air == "Air PDAM") echo 'checked'?>> Air PDAM<br>
<input type="radio" name="air" value="Air Tanah" <?php if($air == "Air Tanah") echo 'checked'?>> Air Tanah
</td>
</tr>
<tr>
<td>Fasilitas</td>
<td>
<input type="checkbox" name="telepon" value="Telepon" <?php if($telepon != "") echo 'checked'?>> Telepon<br>
<input type="checkbox" name="televisi" value="Televisi" <?php if($televisi != "") echo 'checked'?>> Televisi<br>
<input type="checkbox" name="komputer" value="Komputer" <?php if($komputer != "") echo 'checked'?>> Komputer<br>
<input type="checkbox" name="rice_cooker" value="Rice Cooker" <?php if($rice_cooker != "") echo 'checked'?>> Rice Cooker<br>
</td>
</tr>
<tr>
<td></td>
<td align="center" colspan="5">
<input type="submit" name="hitung" value="Hitung">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</form>
</div>

<?php if(isset($_POST['hitung'])){ ?>
<div align="center" style="margin-top: 40px">
<table border="1" width="200">
<tr>
<td align="center" colspan="2">HASIL PERHITUNGAN</td>
</tr>
<tr>
<td style="background-color: gainsboro" align="center" colspan="2">Kamar</td>
</tr>
<tr>
<td width="100">
<?php
if($tipe == "A"){
echo "2 x 3 m";
$biaya_kamar = 200000;
} else if($tipe == "B"){
echo "3 x 3 m";
$biaya_kamar = 250000;
} else if($tipe == "C"){
echo "4 x 3 m";
$biaya_kamar = 300000;
}
?>
</td>
<td width="100">Rp. <?php echo number_format($biaya_kamar, 0, '', '.');?></td>
</tr>
<tr>
<td style="background-color: gainsboro" align="center" colspan="2">Jenis Air</td>
</tr>
<tr>
<td><?php echo $air; ?></td>
<td>
Rp.
<?php
if($air == 'Air PDAM'){
$biaya_air = 20000;
echo number_format($biaya_air, 0, '', '.');
} else {
$biaya_air = 15000;
echo number_format($biaya_air, 0, '', '.');
}
?>
</td>
</tr>
<tr>
<td style="background-color: gainsboro" align="center" colspan="2">Fasilitas-Fasilitas</td>
</tr>
<?php
if($telepon != ""){
$biaya_telepon = 20000;
?>
<tr>
<td>Telepon</td>
<td align="right">Rp. <?php echo number_format($biaya_telepon, 0, '', '.')?></td>
</tr>
<?php
}
if($televisi != ""){
$biaya_televisi = 30000;
?>
<tr>
<td>Televisi</td>
<td align="right">Rp. <?php echo number_format($biaya_televisi, 0, '', '.')?></td>
</tr>
<?php
}
if($komputer != ""){
$biaya_komputer = 60000;
?>
<tr>
<td>Komputer</td>
<td align="right">Rp. <?php echo number_format($biaya_komputer, 0, '', '.')?></td>
</tr>
<?php
}
if($rice_cooker != ""){
$biaya_rice_cooker = 5000;
?>
<tr>
<td>Rice Cooker</td>
<td align="right">Rp. <?php echo number_format($biaya_rice_cooker, 0, '', '.')?></td>
</tr>
<?php
}

$total = $biaya_kamar + $biaya_air + $biaya_telepon + $biaya_televisi + $biaya_komputer + $biaya_rice_cooker;
?>
<tr>
<td style="background-color: gainsboro" align="center">TOTAL</td>
<td style="background-color: gainsboro" align="right"><b>Rp. <?php echo number_format($total, 0, '', '.')?></b></td>
</tr>
</table>
</div>
<?php } ?>
</body>
</html>


0 Comments

Copyright Jujur Soaloon Sitangang Lipan All rights reserved. Theme by Sitanggang. | Bloggerized by Soalparna.