1. Berikut adalah script untuk membuat form input data.
Tampilan form input data ( form_cat.php ) |
<html>
<head>
<h1><font face="Courier New">TOKO CAT GUNA BANGUN JAYA</font></h1>
</head>
<body >
<font face="Courier New"/>
<form action="tampil_output.php" method="POST">
<table>
<tr>
<td>Nama Costumer</td>
<td>:</td>
<td> <input type="text" name="nama" size="30" value=" "></td>
</tr>
<tr>
<td>Alamat</td><td>:</td>
<td> <input type="text" name="alamat" size="30" value=" "></td>
</tr>
<tr>
<td>Jenis Cat</td><td>:</td>
<td> <select name="cat" >
<option value="MOWILEX"> MOWILEX </option>
<option value="DANAPAINT"> DANAPAINT </option>
<option value="CATYLAC"> CATYLAC </option>
</select></td>
</tr>
<tr>
<td>Warna Cat</td><td>:</td>
<td>
<input type="radio" name="warna" value="Merah"/>Merah
<input type="radio" name="warna" value="Biru"/>Biru
<input type="radio" name="warna" value="Kuning"/>Kuning
</td>
</tr>
<tr>
<td>Jumlah Beli</td><td>:</td>
<td> <input type="text" name="beli" size="30" value=" "></td>
</tr>
<tr>
<td><br>
<input type="submit" name="submit" value="Hitung">
<input type="reset" name="reset" value="Batal">
</td>
</tr>
</table>
</form>
</body>
</html>
<head>
<h1><font face="Courier New">TOKO CAT GUNA BANGUN JAYA</font></h1>
</head>
<body >
<font face="Courier New"/>
<form action="tampil_output.php" method="POST">
<table>
<tr>
<td>Nama Costumer</td>
<td>:</td>
<td> <input type="text" name="nama" size="30" value=" "></td>
</tr>
<tr>
<td>Alamat</td><td>:</td>
<td> <input type="text" name="alamat" size="30" value=" "></td>
</tr>
<tr>
<td>Jenis Cat</td><td>:</td>
<td> <select name="cat" >
<option value="MOWILEX"> MOWILEX </option>
<option value="DANAPAINT"> DANAPAINT </option>
<option value="CATYLAC"> CATYLAC </option>
</select></td>
</tr>
<tr>
<td>Warna Cat</td><td>:</td>
<td>
<input type="radio" name="warna" value="Merah"/>Merah
<input type="radio" name="warna" value="Biru"/>Biru
<input type="radio" name="warna" value="Kuning"/>Kuning
</td>
</tr>
<tr>
<td>Jumlah Beli</td><td>:</td>
<td> <input type="text" name="beli" size="30" value=" "></td>
</tr>
<tr>
<td><br>
<input type="submit" name="submit" value="Hitung">
<input type="reset" name="reset" value="Batal">
</td>
</tr>
</table>
</form>
</body>
</html>
2. Berikut adalah script output yang digunakan untuk menampilkan hasil dari form input.
Keterangan pada tampilan output adalah menghitung total pembayaran belanja dengan syarat sebagai berikut.
- Jika belanja cat 5 kaleng sampai 9 kaleng mendapatkan potongan diskon 5%
- Jika belanja cat 10 kaleng atau lebih mendapatkan potongan diskon 10%
- Jika belanja cat 4 kaleng atau dibawahnya tidak mendapatkan potongan diskon
Tampilan output data ( tampil_output.php ) |
<html>
<head>
<h1><font face="Courier New" size="5">TOKO CAT GUNA BANGUN JAYA</font></h1>
<body>
<font face="Courier New"/>
<?php
$nama=$_POST["nama"];
$alamat=$_POST["alamat"];
$cat=$_POST["cat"];
$warna=$_POST["warna"];
$beli=$_POST["beli"];
?>
<table>
<td colspan="4">------------------------------------------------------</td>
<tr>
<td>Nama Costumer</td><td>:</td>
<td> <?php echo $nama;?></td>
</tr>
<tr>
<td>Alamat</td><td>:</td>
<td><?php echo $alamat;?></td>
</tr>
<tr>
<td>Jenis Cat</td><td>:</td>
<td> <?php echo $cat;?></td>
</tr>
<tr>
<td>Warna</td><td>:</td>
<td><?php echo $warna;?></td>
</tr>
<tr>
<td>Harga</td><td> : </td>
<td style="padding-left: 180px">
<?php
if ($cat=="MOWILEX")
{
$MOWILEX=20000;
echo "Rp. $MOWILEX";
}
elseif ($cat=="DANAPAINT")
{
$DANAPAINT=30000;
echo "Rp. $DANAPAINT";
}
elseif ($cat=="CATYLAC")
{
$CATYLAC=40000;
echo "Rp. $CATYLAC";
} ?></td>
</tr>
<tr>
<td>Jumlah Beli</td><td>:</td>
<td><?php echo $beli;?></td>
</tr>
<td colspan="4">------------------------------------------------------ (*)</td>
<tr>
<td>Total Harga</td><td>:</td>
<td style="padding-left:180px">
<?php
if ($cat=="MOWILEX")
{
$tot_harga=$beli*$MOWILEX;
echo "Rp. $tot_harga";
}
elseif ($cat=="DANAPAINT")
{
$tot_harga=$beli*$DANAPAINT;
echo "Rp. $tot_harga";
}
elseif ($cat=="CATYLAC")
{
$tot_harga=$beli*$CATYLAC;
echo "Rp. $tot_harga";
} ?></td>
</tr>
<tr>
<td>Diskon</td><td>:</td>
<td style="padding-left:180px">
<?php
if ($beli>=10)
{
$diskon=(($tot_harga*10)/100);
echo "Rp. $diskon";
}
elseif ($beli>=5)
{
$diskon=(($tot_harga*5)/100);
echo "Rp. $diskon";
}
elseif ($beli<=4)
{
$diskon=0;
echo "Rp. $diskon";
} ?></td>
</tr>
<td colspan="4">------------------------------------------------------ (-)</td>
<tr>
<td>Total Bayar</td><td>:</td>
<td style="padding-left:180px">
<?php $tot_bayar=$tot_harga-$diskon;
echo "Rp. $tot_bayar";
?></td>
</tr>
<td colspan="4">------------------------------------------------------</td>
<tr>
<td></br><a href="form_cat.php">Kembali</a></td>
</tr>
</table>
</body>
</html>
<head>
<h1><font face="Courier New" size="5">TOKO CAT GUNA BANGUN JAYA</font></h1>
<body>
<font face="Courier New"/>
<?php
$nama=$_POST["nama"];
$alamat=$_POST["alamat"];
$cat=$_POST["cat"];
$warna=$_POST["warna"];
$beli=$_POST["beli"];
?>
<table>
<td colspan="4">------------------------------------------------------</td>
<tr>
<td>Nama Costumer</td><td>:</td>
<td> <?php echo $nama;?></td>
</tr>
<tr>
<td>Alamat</td><td>:</td>
<td><?php echo $alamat;?></td>
</tr>
<tr>
<td>Jenis Cat</td><td>:</td>
<td> <?php echo $cat;?></td>
</tr>
<tr>
<td>Warna</td><td>:</td>
<td><?php echo $warna;?></td>
</tr>
<tr>
<td>Harga</td><td> : </td>
<td style="padding-left: 180px">
<?php
if ($cat=="MOWILEX")
{
$MOWILEX=20000;
echo "Rp. $MOWILEX";
}
elseif ($cat=="DANAPAINT")
{
$DANAPAINT=30000;
echo "Rp. $DANAPAINT";
}
elseif ($cat=="CATYLAC")
{
$CATYLAC=40000;
echo "Rp. $CATYLAC";
} ?></td>
</tr>
<tr>
<td>Jumlah Beli</td><td>:</td>
<td><?php echo $beli;?></td>
</tr>
<td colspan="4">------------------------------------------------------ (*)</td>
<tr>
<td>Total Harga</td><td>:</td>
<td style="padding-left:180px">
<?php
if ($cat=="MOWILEX")
{
$tot_harga=$beli*$MOWILEX;
echo "Rp. $tot_harga";
}
elseif ($cat=="DANAPAINT")
{
$tot_harga=$beli*$DANAPAINT;
echo "Rp. $tot_harga";
}
elseif ($cat=="CATYLAC")
{
$tot_harga=$beli*$CATYLAC;
echo "Rp. $tot_harga";
} ?></td>
</tr>
<tr>
<td>Diskon</td><td>:</td>
<td style="padding-left:180px">
<?php
if ($beli>=10)
{
$diskon=(($tot_harga*10)/100);
echo "Rp. $diskon";
}
elseif ($beli>=5)
{
$diskon=(($tot_harga*5)/100);
echo "Rp. $diskon";
}
elseif ($beli<=4)
{
$diskon=0;
echo "Rp. $diskon";
} ?></td>
</tr>
<td colspan="4">------------------------------------------------------ (-)</td>
<tr>
<td>Total Bayar</td><td>:</td>
<td style="padding-left:180px">
<?php $tot_bayar=$tot_harga-$diskon;
echo "Rp. $tot_bayar";
?></td>
</tr>
<td colspan="4">------------------------------------------------------</td>
<tr>
<td></br><a href="form_cat.php">Kembali</a></td>
</tr>
</table>
</body>
</html>
Script di atas sudah dicoba dan berhasil, tetapi belum bisa dikatakan sempurna karena masih ada beberapa yang harus diperbaiki lagi dalam penulisan script nya.
Terima kasih.