EAS MPPL 2021 Pada kesempatan ini kelompok kami akan menjelaskan salah satu produk perangkat lunak milik Zoho yaitu Zoho Marketing Automation yang dikerjakan secara berkelompok yang beranggotakan: Ricky Supriyanto 05111940000036 Arvel Gavrilla R 05111940000040 M Arif Faizin 05111940000060 Zulfiqar Fauzul Akbar 05111940000101 Raihan Alifianto 05111940000213 Dengan hasil sebagai berikut 1. Deskripsi Produk 2. Manajemen Ruang Lingkup 3. Manajemen Waktu 4. Manajemen Biaya 5. Manajemen Resiko 6. Video demo
Pada postingan ini, saya akan menjelaskan cara membuat halaman Pendaftaran Siswa Baru menggunakan PHP
Buat beberapa file untuk menerapkan fungsi PHP sebagai untuk dapat menerapkan fungsi CRUD nya
config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = "localhost"; | |
$user = "root"; | |
$password = ""; | |
$nama_database = "pendaftaran_siswa"; | |
$db = mysqli_connect($server, $user, $password, $nama_database); | |
if (!$db) { | |
die("Gagal terhubung dengan database: " . mysqli_connect_error()); | |
} |
index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pendaftaran Siswa Baru | SMK Coding</title> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="d-flex flex-column px-4 pt-5 min-vh-100 vh-100 text-center border-bottom align-items-center overflow-hidden"> | |
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> | |
<symbol id="check-circle-fill" fill="currentColor" viewBox="0 0 16 16"> | |
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" /> | |
</symbol> | |
<symbol id="info-fill" fill="currentColor" viewBox="0 0 16 16"> | |
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z" /> | |
</symbol> | |
<symbol id="exclamation-triangle-fill" fill="currentColor" viewBox="0 0 16 16"> | |
<path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" /> | |
</symbol> | |
</svg> | |
<?php if (isset($_GET['status'])) : | |
$status = $_GET['status']; | |
?> | |
<div class="alert <?php echo ($status == 'sukses') ? 'alert-success ' : 'alert-danger ' ?>d-flex align-items-center" role="alert"> | |
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="<?php echo ($status == 'sukses') ? 'Success:' : 'Danger:' ?>"> | |
<use xlink:href="<?php echo ($status == 'sukses') ? '#check-circle-fill' : '#exclamation-triangle-fill' ?>" /> | |
</svg> | |
<div> | |
<?php | |
if ($status == 'sukses') { | |
echo "Pendaftaran siswa baru berhasil!"; | |
} else { | |
echo "Pendaftaran gagal!"; | |
} | |
?> | |
</div> | |
</div> | |
<?php endif; ?> | |
<h1 class="display-4 fw-bold">Pendaftaran Siswa Baru</h1> | |
<div class="col-lg-6 mx-auto"> | |
<p class="lead mb-4">Sekolah Menengah Kejuruan Coding (SMK Coding) merupakan sekolah berbasis teknologi dengan berbagai keunggulan, diantaranya adalah kemudahan untuk belajar secara langsung melalui praktek-praktek yang diberikan, fasilitas yang lengkap untuk mendukung pembelajran, serta guru yang berkompeten dalam bidangnya</p> | |
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center mb-5"> | |
<a class="btn btn-primary btn-lg px-4 me-sm-3" href="form-daftar.php">Daftar Baru</a> | |
<a class="btn btn-outline-secondary btn-lg px-4" href="list-siswa.php">Pendaftar</a> | |
</div> | |
</div> | |
<div class="overflow-hidden" style="max-height: 50vh;"> | |
<div class="container px-5"> | |
<img src="img/home-image.jpg" class="img-fluid border rounded-3 shadow-lg mb-4" alt="Example image" loading="lazy" width="700" height="500"> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
form-daftar.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Formulir Pendaftaran Siswa Baru | SMK Coding</title> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="d-flex flex-column pt-5 min-vh-100 text-center border-bottom align-items-center overflow-hidden"> | |
<div class="container row"> | |
<div class="col-lg"> | |
<form action="proses-pendaftaran.php" method="POST"> | |
<div class="card p-5 shadow align-center min-vw-75"> | |
<div class="card-body"> | |
<h2 class="card-title mb-4">Formulir Pendaftaran</h2> | |
<p>Formulir pendaftaran siswa baru SMK Coding</p> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<input type="text" class="form-control" id="floatingNama" name="nama"> | |
<label for="floatingNama">Nama</label> | |
</div> | |
</div> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<select class="form-select" id="floatingJenisKelamin" aria-label="Floating label select" name="jenis_kelamin"> | |
<option disabled selected>Pilih menu</option> | |
<option value="laki-laki">Laki-laki</option> | |
<option value="perempuan">Perempuan</option> | |
</select> | |
<label for="floatingJenisKelamin">Jenis Kelamin</label> | |
</div> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="form-floating mb-3"> | |
<select class="form-select" id="floatingAgama" aria-label="Floating label select" name="agama"> | |
<option disabled selected>Pilih menu</option> | |
<option value="islam">Islam</option> | |
<option value="katolik">Kristen Katolik</option> | |
<option value="protestan">Kristen Protestan</option> | |
<option value="hindu">Hindu</option> | |
<option value="budha">Budha</option> | |
<option value="konghucu">Kong Hu Cu</option> | |
<option value="atheis">Atheis</option> | |
</select> | |
<label for="floatingAgama">Agama</label> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<textarea class="form-control" id="floatingAlamat" style="height: 100px" name="alamat"></textarea> | |
<label for="floatingAlamat">Alamat</label> | |
</div> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<input type="text" class="form-control" id="floatingSekolah" name="sekolah_asal"> | |
<label for="floatingSekolah">Sekolah Asal</label> | |
</div> | |
</div> | |
<button type="submit" value="Daftar" name="daftar" class="btn btn-primary">Submit</button> | |
</div> | |
</div> | |
</div> | |
</form> | |
</div> | |
<div class="d-flex col-lg justify-content-center align-items-center"> | |
<div> | |
<img src="img/daftar-image.png" class="img-fluid rounded-3 mb-4" alt="Example image" loading="lazy"> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
proses-pendaftaran.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// cek apakah tombol daftar sudah diklik atau blum? | |
if (isset($_POST['daftar'])) { | |
// ambil data dari formulir | |
$nama = $_POST['nama']; | |
$alamat = $_POST['alamat']; | |
$jk = $_POST['jenis_kelamin']; | |
$agama = $_POST['agama']; | |
$sekolah = $_POST['sekolah_asal']; | |
// buat query | |
$sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah')"; | |
$query = mysqli_query($db, $sql); | |
// apakah query simpan berhasil? | |
if ($query) { | |
// kalau berhasil alihkan ke halaman index.php dengan status=sukses | |
header('Location: index.php?status=sukses'); | |
} else { | |
// kalau gagal alihkan ke halaman indek.php dengan status=gagal | |
header('Location: index.php?status=gagal'); | |
} | |
} else { | |
die("Akses dilarang..."); | |
} |
list-siswa.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php include("config.php"); ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pendaftaran Siswa Baru | SMK Coding</title> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="d-flex flex-column px-4 pt-5 min-vh-100 text-center border-bottom align-items-center"> | |
<header class="fs-1"> | |
<h1>Daftar Siswa Pendaftar</h1> | |
</header> | |
<div class="text-start w-100 w-md-auto"> | |
<nav> | |
<a class="btn btn-primary" href="form-daftar.php">Tambah Baru</a> | |
</nav> | |
<div class="table-responsive"> | |
<table class="table table-striped"> | |
<thead> | |
<tr> | |
<th scope="col">No</th> | |
<th scope="col">Nama</th> | |
<th scope="col">Alamat</th> | |
<th scope="col">Jenis Kelamin</th> | |
<th scope="col">Agama</th> | |
<th scope="col">Sekolah Asal</th> | |
<th scope="col">Tindakan</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
$sql = "SELECT * FROM calon_siswa"; | |
$query = mysqli_query($db, $sql); | |
while ($siswa = mysqli_fetch_array($query)) { | |
echo "<tr scope='row'>"; | |
echo "<td>" . $siswa['id'] . "</td>"; | |
echo "<td>" . $siswa['nama'] . "</td>"; | |
echo "<td>" . $siswa['alamat'] . "</td>"; | |
echo "<td>" . $siswa['jenis_kelamin'] . "</td>"; | |
echo "<td>" . $siswa['agama'] . "</td>"; | |
echo "<td>" . $siswa['sekolah_asal'] . "</td>"; | |
echo "<td>"; | |
echo "<a href='form-edit.php?id=" . $siswa['id'] . "'>Edit</a> | "; | |
echo "<a href='hapus.php?id=" . $siswa['id'] . "'>Hapus</a>"; | |
echo "</td>"; | |
echo "</tr>"; | |
} | |
?> | |
</tbody> | |
</table> | |
</div> | |
<p>Total: <?php echo mysqli_num_rows($query) ?></p> | |
</div> | |
</div> | |
</body> | |
</html> |
form-edit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// kalau tidak ada id di query string | |
if (!isset($_GET['id'])) { | |
header('Location: list-siswa.php'); | |
} | |
//ambil id dari query string | |
$id = $_GET['id']; | |
// buat query untuk ambil data dari database | |
$sql = "SELECT * FROM calon_siswa WHERE id=$id"; | |
$query = mysqli_query($db, $sql); | |
$siswa = mysqli_fetch_assoc($query); | |
// jika data yang di-edit tidak ditemukan | |
if (mysqli_num_rows($query) < 1) { | |
die("data tidak ditemukan..."); | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Formulir Edit Siswa | SMK Coding</title> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="d-flex flex-column pt-5 min-vh-100 text-center border-bottom align-items-center overflow-hidden"> | |
<div class="container row"> | |
<div class="d-flex col-lg justify-content-center align-items-center"> | |
<div> | |
<img src="img/daftar-image.png" class="img-fluid rounded-3 mb-4" alt="Example image" loading="lazy"> | |
</div> | |
</div> | |
<div class="col-lg"> | |
<form action="proses-edit.php" method="POST"> | |
<div class="card p-5 shadow align-center min-vw-75"> | |
<div class="card-body"> | |
<h2 class="card-title mb-4">Formulir Edit</h2> | |
<p>Formulir edit siswa baru SMK Coding</p> | |
<input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" /> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<input type="text" class="form-control" id="floatingNama" name="nama" value="<?php echo $siswa['nama'] ?>"> | |
<label for="floatingNama">Nama</label> | |
</div> | |
</div> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<select class="form-select" id="floatingJenisKelamin" aria-label="Floating label select" name="jenis_kelamin"> | |
<?php $jenis_kelamin = $siswa['jenis_kelamin']; ?> | |
<option disabled>Pilih menu</option> | |
<option value="laki-laki" <?php echo ($jenis_kelamin == 'laki-laki') ? "selected" : "" ?>>Laki-laki</option> | |
<option value="perempuan" <?php echo ($jenis_kelamin == 'perempuan') ? "selected" : "" ?>>Perempuan</option> | |
</select> | |
<label for="floatingJenisKelamin">Jenis Kelamin</label> | |
</div> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="form-floating mb-3"> | |
<select class="form-select" id="floatingAgama" aria-label="Floating label select" name="agama"> | |
<?php $agama = $siswa['agama']; ?> | |
<option disabled>Pilih menu</option> | |
<option <?php echo ($agama == 'islam') ? "selected" : "" ?>>Islam</option> | |
<option <?php echo ($agama == 'katolik') ? "selected" : "" ?>>Kristen Katolik</option> | |
<option <?php echo ($agama == 'protestan') ? "selected" : "" ?>>Kristen Protestan</option> | |
<option <?php echo ($agama == 'hindu') ? "selected" : "" ?>>Hindu</option> | |
<option <?php echo ($agama == 'budha') ? "selected" : "" ?>>Budha</option> | |
<option <?php echo ($agama == 'konghucu') ? "selected" : "" ?>>Kong Hu Cu</option> | |
<option <?php echo ($agama == 'atheis') ? "selected" : "" ?>>Atheis</option> | |
</select> | |
<label for="floatingAgama">Agama</label> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<textarea class="form-control" id="floatingAlamat" style="height: 100px" name="alamat"><?php echo $siswa['alamat'] ?></textarea> | |
<label for="floatingAlamat">Alamat</label> | |
</div> | |
</div> | |
</div> | |
<div class="row g-2"> | |
<div class="col-md"> | |
<div class="form-floating mb-3"> | |
<input type="text" class="form-control" id="floatingSekolah" name="sekolah_asal" value="<?php echo $siswa['sekolah_asal'] ?>"> | |
<label for="floatingSekolah">Sekolah Asal</label> | |
</div> | |
</div> | |
<button type="submit" value="Daftar" name="simpan" class="btn btn-primary">Simpan</button> | |
</div> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
proses-edit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// cek apakah tombol simpan sudah diklik atau blum? | |
if (isset($_POST['simpan'])) { | |
// ambil data dari formulir | |
$id = $_POST['id']; | |
$nama = $_POST['nama']; | |
$alamat = $_POST['alamat']; | |
$jenis_kelamin = $_POST['jenis_kelamin']; | |
$agama = $_POST['agama']; | |
$sekolah = $_POST['sekolah_asal']; | |
// buat query update | |
$sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jenis_kelamin', agama='$agama', sekolah_asal='$sekolah' WHERE id=$id"; | |
$query = mysqli_query($db, $sql); | |
// apakah query update berhasil? | |
if ($query) { | |
// kalau berhasil alihkan ke halaman list-siswa.php | |
header('Location: list-siswa.php'); | |
} else { | |
// kalau gagal tampilkan pesan | |
die("Gagal menyimpan perubahan..."); | |
} | |
} else { | |
die("Akses dilarang..."); | |
} |
hapus.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
if (isset($_GET['id'])) { | |
// ambil id dari query string | |
$id = $_GET['id']; | |
// buat query hapus | |
$sql = "DELETE FROM calon_siswa WHERE id=$id"; | |
$query = mysqli_query($db, $sql); | |
// apakah query hapus berhasil? | |
if ($query) { | |
header('Location: list-siswa.php'); | |
} else { | |
die("gagal menghapus..."); | |
} | |
} else { | |
die("akses dilarang..."); | |
} |
Berikut adalah beberapa tampilan hasil dari operasi menggunakan PHP tersebut
Sekian postingan kali ini, terima kasih.
Comments
Post a Comment