Tugas CRUD Pendaftaran Siswa Baru - PPDB Kabupaten Pamekasan 2022
22 Desember 2022
Blog ini merupakan dokumentasi pengerjaan tugas CRUD untuk membuat website pendaftaran siswa baru.
Disini saya membuat website dengan tema PPDB Kabupaten Pamekasan. Menggunakan HTML, CSS, dan JS sebagai frontend serta PHP sebagai backend. Pada website ini kita bisa melakukan pendaftaran siswa baru melalui form dan melihat list pendaftar. Pada setiap pendaftar kita bisa melakukan edit dan hapus data.
Schema Database
Screenshot Demo
Backend Algorithm
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 | |
$host = "localhost"; | |
$dbname = "ppdb-pamekasan"; | |
$user = "root"; | |
$password = ""; | |
$conn = mysqli_connect($host, $user, $password, $dbname); | |
if (!$conn){ | |
die("<script>alert('Gagal menyambungkan ke server!') </script>"); | |
} | |
?> |
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"; | |
function query($query){ | |
global $conn; | |
$get = mysqli_query($conn, $query); | |
$rows = []; | |
while($row = mysqli_fetch_assoc($get)){ | |
$rows[] = $row; | |
} | |
return $rows; | |
} | |
function getNewId() { | |
$query = "SELECT max(id) as id from calon_siswa"; | |
$latestId = query($query)[0]['id']; | |
$latestId = (int) substr($latestId, 2); | |
$latestId++; | |
$newId = "CS".str_pad($latestId, 4, "0", STR_PAD_LEFT); | |
return $newId; | |
} | |
?> |
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
<script src="https://code.jquery.com/jquery-3.6.2.min.js" integrity="sha256-2krYZKh//PcchRtd+H+VyyQoZ/e3EcrkxhM8ycwASPA=" crossorigin="anonymous"></script> | |
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
<?php | |
include "./config.php"; | |
include "./functions.php"; | |
$id = $_POST['id']; | |
$name = $_POST['name']; | |
$address = $_POST['address']; | |
$sex = $_POST['sex']; | |
$religion = $_POST['religion']; | |
$previous_school = $_POST['previous-school']; | |
$update_query = "UPDATE calon_siswa SET nama='$name', alamat='$address', jenis_kelamin='$sex', agama='$religion', sekolah_asal='$previous_school' WHERE id='$id'"; | |
$update = mysqli_query($conn, $update_query); | |
if ($update){ | |
echo '<script type="text/javascript"> | |
$(document).ready(function(){ | |
Swal.fire({ | |
icon: "success", | |
title: "Berhasil", | |
text: "Update data berhasil!", | |
}).then((result) => { | |
if (result.isConfirmed) { | |
document.location.href="../index.php"; | |
} | |
}); | |
}) | |
</script>'; | |
} | |
?> |
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
<script src="https://code.jquery.com/jquery-3.6.2.min.js" integrity="sha256-2krYZKh//PcchRtd+H+VyyQoZ/e3EcrkxhM8ycwASPA=" crossorigin="anonymous"></script> | |
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
<?php | |
include "./config.php"; | |
$id = $_GET['id']; | |
$delete_query = "DELETE FROM calon_siswa WHERE id='$id'"; | |
$delete = mysqli_query($conn, $delete_query); | |
if ($delete){ | |
echo '<script type="text/javascript"> | |
$(document).ready(function(){ | |
Swal.fire({ | |
icon: "success", | |
title: "Berhasil", | |
text: "Data calon siswa berhasil dihapus", | |
}).then((result) => { | |
if (result.isConfirmed) { | |
document.location.href="../list-pendaftar.php"; | |
} | |
}); | |
}) | |
</script>'; | |
} | |
?> |
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
<script src="https://code.jquery.com/jquery-3.6.2.min.js" integrity="sha256-2krYZKh//PcchRtd+H+VyyQoZ/e3EcrkxhM8ycwASPA=" crossorigin="anonymous"></script> | |
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> | |
<?php | |
include "./config.php"; | |
include "./functions.php"; | |
$id = getNewId(); | |
$name = $_POST['name']; | |
$address = $_POST['address']; | |
$sex = $_POST['sex']; | |
$religion = $_POST['religion']; | |
$previous_school = $_POST['previous-school']; | |
$insert_query = "INSERT INTO calon_siswa (id, nama, alamat, jenis_kelamin, agama, sekolah_asal) VALUES ('$id', '$name', '$address', '$sex', '$religion', '$previous_school')"; | |
$insert = mysqli_query($conn, $insert_query); | |
if ($insert){ | |
echo '<script type="text/javascript"> | |
$(document).ready(function(){ | |
Swal.fire({ | |
icon: "success", | |
title: "Berhasil", | |
text: "Selamat, registrasi berhasil!", | |
}).then((result) => { | |
if (result.isConfirmed) { | |
document.location.href="../index.php"; | |
} | |
}); | |
}) | |
</script>'; | |
}else{ | |
echo '<script type="text/javascript"> | |
$(document).ready(function(){ | |
Swal.fire({ | |
icon: "error", | |
title: "Gagal", | |
text: "Woops! Terjadi kesalahan.", | |
}).then((result) => { | |
if (result.isConfirmed) { | |
} | |
}); | |
}) | |
</script>'; | |
} | |
?> |
Nama : Arief Badrus Sholeh
NRP : 5025201228
Kelas : Pemrograman Web A
Tahun : 2022/2023
Komentar
Posting Komentar