MODUL VI
“Laporan ini disusun untuk memenuhi tugas mata kuliah “Praktikkum Pemograman Web”
yang diampu oleh Ibu Yati Nuhayati, S.Kom.,M.Kom.”
Disusun oleh:
UNIVERSITAS KUNINGAN
KUNINGAN
2022
PRETEST
1. Apa perbedaan javascript dan php?
Jawab : JavaScript biasanya digunakan sebagai pembantu interface (tampilan) sehingga
halaman website lebih interaktif, seperti pembuatan animasi, menagani event yang
dilakukan user dan berbagai fungsi lainnya. Sedangkan PHP digunakan untuk membuat
web dinamis yang membutuhkan manajemen data, seperti database, upload file dan
masih banyak lagi.
2. Buat script PHP untuk menginputkan dan menampilkan biodata anda menggunakan
Jawab :
<!DOCTYPE html>
<html>
<head>
<title>Pretest</title>
</head>
<body>
<form name="form1" method="post">
      <b>Form Biodata</b><br><br>
Nim <input type="text" name="nim"><br><br>
Nama <input type="text" name="nama"><br><br>
Prodi <input type="text" name="prodi"><br><br>
<input type="submit" name="tampil" value="Sumbit">
<br> <br><br>
<?php
extract($_POST);
if(isset($tampil)){
echo "<b>====Biodata Anda====</b><br><br>";
echo "Nama : $nama <br>";
echo "Nim : $nim <br>";
echo "Prodi : $prodi <br>";
}
?>
</form>
</body>
</html>
PRAKTIKUM
prak6_1
<!DOCTYPE html>
<html>
<head>
<title>Modul 5 Praktikum 1</title>
</head>
<body text="white" bgcolor="pink">
<?php
echo "<center>
<font color='yellow' size='6'>Uniku Jaya</font>
<br><b>FKOM Jaya</b><br>
<font color='blue' size='5'><i>Teknik Informatika</i>
<b>Prestasi</b></font> !!
</center>";
?>
</body>
</html>
prak6_2
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 2</title>
</head>
<body>
<?php
$a = 10;
$b = 5;
$c = $a;
$d = $a * $b;
$e = pow($a,2);
$f = $b%2;
$g = ($e * $f) + $b - $c * $f / $a ;
$h = sqrt($a);
$i = 8.96;
$j = "Teknik Informatika";
$k = "A";
$l = $f;
<?php
if(isset($tombol)){
echo "<br><br>Menampilkan Nama Di Bawah Form : <br>
Nama Anda = ".$_GET['nama']. "<br>";
}
?>
</body>
</html>
prak6_3c
<?php
$a = "";
if(isset($_POST["tombol"])){
$a = $_POST["nama"];
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 3C</title>
</head>
<body>
<form name="form1" method="post">
Nama <input type="text" name="nama" id="NAMA" value="<?php echo $a; ?
>"> <br>
<input type="submit" name="tombol" value="SHOW">
</form>
</body>
</html>
prak6_4a
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 4A</title>
</head>
<body>
<form name="form1" method="post">
Bilangan 1 <input type="number" name="bil_1"> <br>
+ <br>
Bilangan 2 <input type="number" name="bil_2"> <br>
<input type="submit" name="hitung" value="=">
<br>
<?php
extract($_POST);
if(isset($hitung)) {
$bil_3 = $bil_1 + $bil_2;
echo "Hasil Penjumlahan $bil_1 + $bil_2 = $bil_3";
}
?>
</form>
</body>
</html>
prak6_4b
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 4B</title>
</head>
<body>
<form name="form1" method="post">
Bilangan 1 <input type="number" name="bil_1"> <br>
+ <br>
Bilangan 2 <input type="number" name="bil_2"> <br>
<input type="submit" name="hitung" value="=">
<br>
<?php
extract($_POST);
if(isset($hitung)) {
$bil_3 = $bil_1 + $bil_2;
echo "Hasil $bil_1 + $bil_2 = <input type=number name=hasil
value=$bil_3>";
}
?>
</form>
</body>
</html>
prak6_4c
<?php
extract($_GET);
$a = "";
$b = "";
$bil_3 = "";
if(isset($hitung)) {
$a = $bil_1;
$b = $bil_2;
$bil_3 = $bil_1 + $bil_2;
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 4C</title>
</head>
<body>
<form name="form1" method="get">
Bilangan 1 <input type="number" name="bil_1" value="<?php echo $a; ?
>"><br>
+ <br>
Bilangan 2 <input type="number" name="bil_2" value="<?php echo $b; ?
>">
<br>
Hasil <input type="number" name="hasil" value="<?php echo $bil_3;
?>" readonly>
</form>
</body>
</html>
prak6_5a
<?php
extract($_POST);
if(isset($tombol_cek)) {
if($bilangan<0 || $bilangan>=50){
echo "<script> alert(Nilai yang Diinjutkan Hanya 0 s.d '45' ):
</script>";
}
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 5A</title>
</head>
<body>
<form name="form1" method="post">
Menentukan Jenis Bilangan <br>
Masukan Bilangan : <input type="number" name="bilangan">
<input type="SUBMIT" name="tombol_cek" value="cek">
</form>
</body>
</html>
prak6_5b
<?php
extract($_POST);
if(isset($tombol_cek)) {
if($bilangan%2==0) {
echo "<script> alert('$bilangan Termasuk Bilangan Genap');
</script>";
}
else {
echo "<script> alert('$bilangan Termasuk Bilangan Ganjil');
</script>";
}
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 5B</title>
</head>
<body>
<form name="form1" method="post">
Menentukan Jenis Bilangan <br>
Masukan Bilangan : <input type="number" value="bilangan">
<input type="SUBMIT" name="tombol_cek" value="cek">
</form>
</body>
</html>
prak6_5c
<?php
extract($_POST);
$HASIL = "";
if(isset($tombol_cek)){
if($bilangan%2==0){
$HASIL = "$bilangan Termasuk Bilangan Genap";
}
else {
$HASIL = "$bilangan Termasuk Bilangan Ganjil";
}
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 5C</title>
</head>
<body>
<form name="form1" method="post">
Menentukan Jenis Bilangan <br>
Masukan Bilangan : <input type="number" name="bilangan">
<br>
<input type="SUBMIT" name="tombol_cek" value="cek">
<br><br>
Jenis Bilangan : <input type="text" name="hasil_cek" value="<?php echo
$HASIL; ?>" readonly size="35">
</form>
</body>
</html>
prak6_5d
<?php
extract($_GET);
$na = "";
if(isset($tampil)) {
if($nilai_huruf=="A"){
$na = 4;
}
else if($nilai_huruf=="B"){
$na = 3;
}
else if($nilai_huruf=="C"){
$na = 2;
}
else if($nilai_huruf=="D"){
$na = 1;
}
else if($nilai_huruf=="E"){
$na = 0;
}
}
?>
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 5D</title>
</head>
<body>
<form name="form1" method="get">
Pilih Nilai Anda :
<select name="nilai_huruf">
<option value="_">--Pilih Salah Satu--</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
<br>
<input type="submit" name="tampil" value="SHOW">
<br><BR>
Nilai Mutu : <input type="text" name="nilai_huryf" readonly value="<?php echo
$na; ?>">
</form>
</body>
</html>
prak6_6
<?php
extract($_GET);
$na = "";
if(isset($tampil)) {
switch($nilai_huruf){
case "A" : $na = 4; break;
case "B" : $na = 3; break;
case "C" : $na = 2; break;
case "D" : $na = 1; break;
case "E" : $na = 0; break;
default : $na = "";
}
}
?>
<!DOCTYPE html>
<head>
<title>Modul 5 Praktikum 6</title>
</head>
<body>
<form name="form1" method="get">
Pilih Nilai Anda :
<select name="nilai_huruf">
<option value="_">--Pilih Salah Satu--</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
<br>
<input type="submit" name="tampil" value="SHOW">
<br><BR>
Nilai Mutu : <input type="text" name="nilai_angka" readonly value="<?php echo
$na; ?>">
</form>
</body>
</html>
prak6_7a
<?php
for ($i=0; $i<=4; $i++)
{
echo "$i <BR>";
}
?>
prak6_7b
<?php
$i=0;
while($i<=4)
{
echo "$i <BR>";
$i++;
}
?>
prak6_7c
<?php
$i=0;
do{
echo "$i <BR>";
$i++;
}
while ($i <= 4);
?>
prak6_7d
<?php
$warna = ["Hitam", "Biru", "Hijau", "Putih"];
$angka = [5, 7.5, 8, 10.5];
unset($warna[2]);
$warna[3]="Merah";
foreach($warna as $wr){
echo "$wr <br>";
}
echo "<p>Menampilkan seluruh angka : </p>";
foreach($angka as $ak){
echo "$ak <br>";
}
?>
prak6_7e
<!DOCTYPE html>
<head>
<title>Modul 6 Praktikum 7E</title>
</head>
<body>
<form name="form1" method="post">
Warna Favorit : <br>
<input type="checkbox" name="wf[]" value="Hitam">Hitam<br>
<input type="checkbox" name="wf[]" value="Putih">Putih<br>
<input type="checkbox" name="wf[]" value="Hijau">Hijau<br>
<input type="checkbox" name="wf[]" value="Biru">Biru<br>
<br><br>
Makanan Favorit : <br>
<input type="radio" name="mt[]" value="Nasi Goreng">Nasi Goreng<br>
<input type="radio" name="mt[]" value="Rendang">Rendang<br>
<input type="radio" name="mt[]" value="Ayam Bakar">Ayam Bakar<br>
<input type="radio" name="mt[]" value="Bakso">Bakso<br>
<br><br>
<input type="submit" name="tampil" value="SHOW">
</form1>
</body>
</html>
<?php
extract($_POST);
if(isset($tampil)) {
echo "<br>Warna Favorit Anda : </br><br>";
foreach($wf as $warna) {
echo $warna. "<BR>";
}
echo "<br>Makanan Favorit Anda : </br><br>";
foreach($mt as $makanan) {
echo $makanan. "<BR>";
}
}
?>
prak6_7f
<?php
$A = [[1,2,4], [3,5,7]];
echo "<br>=====================================<br>";
echo "<p>baris ke-0 kolo ke-2 : ".$A[0][2];
?>
POSTTEST
1. Buatlah script php untuk menghitung gaji pegawai dengan kasus sebagai berikut :
<?php
if(isset($_POST['hitung'])) {
$golongan = $_POST['gol'];
$jumlahAnak = $_POST['anak'];
if($golongan == 'I') {
$gaji_pokok = 200000;
$persen_tunjangan = 0.05;
} else if ($golongan == 'II') {
$gaji_pokok = 400000;
$persen_tunjangan = 0.01;
} else if ($golongan == 'III'){
$gaji_pokok = 500000;
$persen_tunjangan = 0.15;
}
$tunjangan = ($jumlahAnak * $gaji_pokok) * $persen_tunjangan;
$gajiBersih = $gaji_pokok + $tunjangan;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Menghitung Gaji Karyawan</title>
</head>
<body>
<form action="" method="POST" name="form1">
<table border="1" cellpadding="3">
<tr>
<td colspan="2">PERHITUNGAN GAJI</td>
</tr>
<tr>
<td> GOLONGAN</td>
<td>
<select name="gol">
<option value="I">I</option>
<option value="II">II</option>
<option value="III">III</option>
</select>
</td>
</tr>
<tr>
<td>Jumlah Anak</td>
<td><input type="number" name="anak" size="10"
maxlength="10"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="hitung" value="hitung"
onclick="hit()">
<input type="reset" name="Batal" value="cancel">
</td>
</tr>
<tr>
<td>Gaji Pokok</td>
<td><input type="number" name="gapok" value="<?php echo
$gaji_pokok?>" size="10"></td>
<tr>
<td>Tunjangan</td>
<td><input type="number" name="tunjangan"value="<?php echo
$tunjangan?>" size="10"></td>
</tr>
<tr>
<td>Gaji Bersih</td>
<td><input type="number" name="gaji"value="<?php echo
$gajiBersih?>" size="10"></td>
</tr>
TUGAS
1. apa yang dimaksud dengan web dinamis ?
Jawab : web dinamis yaitu sebuah tampilan web dimana tidak hanya dapat dinikmati
tampilannya saja tetapi memiliki fungsi dan kegunaan untuk menginputkan atau
memberikan suatu aksi tertentu supaya mendaptkan sebuah output yang diinginkan.
?>
<!DOCTYPE html>
<head>
<title>Tugas</title>
</head>
<body>
<form name="form1" method="post">
<input type="SUBMIT" name="tombol_cek" value="Masuk">
</form>
</body>
</html>
4. Buatlah script php untuk menghitung dan menampilkan hasil penjualan dengan kasus
sebagai berikut :
<?php
extract($_POST);
$namabarang = "";
$harga = "";
$jumlahbayar = "";
$potongan = "";
$totalbayar = "";
$diskon = "";
if(isset($tampil)){
if($kode = "B001"){
$namabarang == "Buku";
$harga = 5000;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
if($kode == "B002"){
$namabarang = "Penggaris";
$harga = 1500;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
if($kode == "B003"){
$namabarang = "Pulpen";
$harga = 2000;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
}
?>
<!DOCTYPE html>
<head>
<title>Tugas</title>
</head>
<body style="padding: 20px;">
<form name="form1" action="" method="post">
<table border="1">
<tr>
<th colspan="2">Data Penjualan Barang</th>
</tr>
<tr>
<td>Kode</td>
<td>
<select name="kode" id="">
<option value="-">--Pilih Salah Satu--</option>
<option value="B001">B001</option>
<option value="B002">B002</option>
<option value="B003">B003</option>
</select>
</td>
</tr>
<tr>
<td>Jumlah Beli</td>
<td><input type="number" name="jumlahbeli" size="25px"
value="<?php echo $jumlahbeli; ?>" ></td>
</tr>
<tr>
<td>Nama Barang</td>
<td><input type="text" name="namabarang" size="25px" value="<?
php echo $namabarang; ?>"></td>
</tr>
<tr>
</form>
<td>Harga</td>
<td><input type="text" name="harga" size="25px" value="<?php
echo $harga; ?>"></td>
</tr>
<tr>
<td>Jumlah Bayar</td>
<td><input type="text" name="jumlahbayar" size="25px"
value="<?php echo $jumlahbayar; ?>"></td>
</tr>
<tr>
<td>Potongan<input type="text" name="diskon" size="10px"
value="<?php echo $diskon; ?>">%</td>
<td><input type="text" name="potongan" size="25px" value="<?
php echo $potongan; ?>"></td>
</tr>
<tr>
<td>Total Bayar</td>
<td><input type="text" name="totalbayar" size="25px" value="<?
php echo $totalbayar; ?>"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="tampil"
value="TAMPILKAN"></center></td>
</tr>
</table>
</form>
<?php
extract($_POST);
$namabarang = "";
$harga = "";
$jumlahbayar = "";
$potongan = "";
$totalbayar = "";
$diskon = "";
if(isset($tampil)) {
if($kode == "B001"){
$namabarang = "Buku";
$harga = 5000;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
if($kode == "B002"){
$namabarang = "Penggaris";
$harga = 1500;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
if($kode == "B003"){
$namabarang = "Pulpen";
$harga = 2000;
if($jumlahbeli >= 0){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.05 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 5;
}
if($jumlahbeli >= 11){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.10 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 10;
}
if($jumlahbeli > 20){
$jumlahbayar = $jumlahbeli * $harga;
$potongan = 0.15 * $jumlahbayar;
$totalbayar = $jumlahbayar - $potongan;
$diskon = 15;
}
}
echo "<br><br>";
echo "<b>Nota Penjualan </b> <br><br>";
echo "Kode Barang : $kode
<br>";
echo "Nama Barang : $namabarang <br>";
echo "Harga Barang : $harga <br>";
echo "Jumlah Beli
: $jumlahbeli<br>";
echo "--------------------------------<br>";
echo "Jumlah Bayar :
$jumlahbayar <br>";
echo "Potongan
:
$potongan <br>";
echo "================================<br>";
echo "Total Bayar
: $totalbayar <br>";
}
?>
</body>
</html>