Tugas Pertemuan 12 PWEB

Nama  : Moh. Rizky Rahmadian Makkani

NRP    : 5025231035

Kelas : PWEB E

Tugas Pertemuan 12 : PWEB


Output :






index.php
<!DOCTYPE html>
<html>
<head>
    <title>Pendaftaran Siswa Baru | SMK Coding</title>
</head>

<body>
    <style>
        /* Reset style */
body, h1, h3, h4, ul, li, a {
    margin: 0;
    padding: 0;
    list-style: none;
    text-decoration: none;
    font-family: Arial, sans-serif;
}

/* Body style */
body {
    background-color: #f5f5f5;
    color: #333;
    padding: 20px;
}

/* Header style */
header {
    background-color: #007acc;
    color: #fff;
    text-align: center;
    padding: 20px 0;
    border-radius: 10px;
    margin-bottom: 20px;
}

header h1 {
    font-size: 2em;
    margin-bottom: 10px;
}

header h3 {
    font-weight: normal;
    font-size: 1.2em;
}

h4 {
    text-align: center
}

/* Navigation style */
nav ul {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

nav ul li {
    list-style: none;
}

nav ul li a {
    display: block;
    padding: 10px 20px;
    background-color: #007acc;
    color: #fff;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

nav ul li a:hover {
    background-color: #005fa3;
}
</style>
    <header>
        <h3>Pendaftaran Siswa Baru</h3>
        <h1>SMK Coding</h1>
    </header>

    <h4>Menu</h4>
    <nav>
        <ul>
            <li><a href="form-daftar.php">Pendaftaran Baru</a></li>
            <li><a href="list-siswa.php">Pendaftar</a></li>
            <li><a href="list-karyawan.php">List Karyawan</a></li>
        </ul>
    </nav>

    </body>
</html>

form-daftar.php
<!DOCTYPE html>
<html>
<head>
    <title>Formulir Pendaftaran Siswa Baru | SMK Coding</title>
</head>

<body>
    <style>
    <style>
        /* General Reset */
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-color: #f4f4f9;
        color: #333;
    }

    /* Header Styling */
    header {
        background-color: #007BFF;
        color: white;
        padding: 20px;
        text-align: center;
        border-bottom: 3px solid #0056b3;
    }

    header h3 {
        margin: 0;
        font-size: 1.5em;
    }

    /* Form Container */
    form {
        max-width: 600px;
        margin: 30px auto;
        background: #ffffff;
        padding: 20px;
        border: 1px solid #ddd;
        border-radius: 5px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    /* Fieldset Styling */
    fieldset {
        border: none;
        padding: 0;
    }

    /* Input Styling */
    p {
        margin-bottom: 15px;
    }

    label {
        display: block;
        font-weight: bold;
        margin-bottom: 5px;
    }

    input[type="text"],
    textarea,
    select {
        width: 100%;
        padding: 10px;
        margin-top: 5px;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 1em;
        box-sizing: border-box;
        background: #f9f9f9;
    }

    textarea {
        resize: vertical;
        height: 100px;
    }

    input[type="radio"] {
        margin-right: 10px;
    }

    /* Button Styling */
    input[type="submit"] {
        display: inline-block;
        background-color: #28a745;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        font-size: 1em;
        cursor: pointer;
        transition: background-color 0.3s;
    }

    input[type="submit"]:hover {
        background-color: #218838;
    }

    /* Form Layout Adjustments */
    p:last-child {
        text-align: right;
    }

    /* Responsive Design */
    @media (max-width: 768px) {
        body {
            font-size: 16px;
        }

        form {
            margin: 20px;
            padding: 15px;
        }

        input[type="submit"] {
            width
    </style>
    <header>
        <h3>Formulir Pendaftaran Siswa Baru</h3>
    </header>

    <form action="proses-pendaftaran.php" method="POST">

        <fieldset>

        <p>
            <label for="nama">Nama: </label>
            <input type="text" name="nama" placeholder="nama lengkap" />
        </p>
        <p>
            <label for="alamat">Alamat: </label>
            <textarea name="alamat"></textarea>
        </p>
        <p>
            <label for="jenis_kelamin">Jenis Kelamin: </label>
            <label><input type="radio" name="jenis_kelamin" value="laki-laki"> Laki-laki</label>
            <label><input type="radio" name="jenis_kelamin" value="perempuan"> Perempuan</label>
        </p>
        <p>
            <label for="agama">Agama: </label>
            <select name="agama">
                <option>Islam</option>
                <option>Kristen</option>
                <option>Hindu</option>
                <option>Budha</option>
                <option>Atheis</option>
            </select>
        </p>
        <p>
            <label for="sekolah_asal">Sekolah Asal: </label>
            <input type="text" name="sekolah_asal" placeholder="nama sekolah" />
        </p>
        <p>
            <label for="karyawan">Karyawan: </label>
            <select name="karyawan">
                <?php
                include("config.php");
                $sql = "SELECT id, nama FROM karyawan";
                $query = mysqli_query($db, $sql);

                while ($karyawan = mysqli_fetch_array($query)) {
                    echo "<option value='".$karyawan['id']."'>".$karyawan['nama']."</option>";
                }
                ?>
            </select>
        </p>
        <p>
            <input type="submit" value="Daftar" name="daftar" />
        </p>

        </fieldset>

    </form>

    </body>
</html>

form-edit.php
<?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>
</head>

<body>
    <style>
        /* General Reset */
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-color: #f4f4f9;
        color: #333;
    }

    /* Header Styling */
    header {
        background-color: #007BFF;
        color: white;
        padding: 20px;
        text-align: center;
        border-bottom: 3px solid #0056b3;
    }

    header h3 {
        margin: 0;
        font-size: 1.5em;
    }

    /* Form Container */
    form {
        max-width: 600px;
        margin: 30px auto;
        background: #ffffff;
        padding: 20px;
        border: 1px solid #ddd;
        border-radius: 5px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    /* Fieldset Styling */
    fieldset {
        border: none;
        padding: 0;
    }

    /* Input Styling */
    p {
        margin-bottom: 15px;
    }

    label {
        display: block;
        font-weight: bold;
        margin-bottom: 5px;
    }

    input[type="text"],
    textarea,
    select {
        width: 100%;
        padding: 10px;
        margin-top: 5px;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 1em;
        box-sizing: border-box;
        background: #f9f9f9;
    }

    textarea {
        resize: vertical;
        height: 100px;
    }

    input[type="radio"] {
        margin-right: 10px;
    }

    /* Button Styling */
    input[type="submit"] {
        display: inline-block;
        background-color: #28a745;
        color: white;
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        font-size: 1em;
        cursor: pointer;
        transition: background-color 0.3s;
    }

    input[type="submit"]:hover {
        background-color: #218838;
    }

    /* Form Layout Adjustments */
    p:last-child {
        text-align: right;
    }

    /* Responsive Design */
    @media (max-width: 768px) {
        body {
            font-size: 16px;
        }

        form {
            margin: 20px;
            padding: 15px;
        }

        input[type="submit"] {
            width
    </style>
    <header>
        <h3>Formulir Edit Siswa</h3>
    </header>

    <form action="proses-edit.php" method="POST">

        <fieldset>

            <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />

            <p>
                <label for="nama">Nama: </label>
                <input type="text" name="nama" placeholder="nama lengkap" value="<?php echo $siswa['nama'] ?>" />
            </p>
            <p>
                <label for="alamat">Alamat: </label>
                <textarea name="alamat"><?php echo $siswa['alamat'] ?></textarea>
            </p>
            <p>
                <label for="jenis_kelamin">Jenis Kelamin: </label>
                <?php $jk = $siswa['jenis_kelamin']; ?>
                <label><input type="radio" name="jenis_kelamin" value="laki-laki" <?php echo ($jk == 'laki-laki') ? "checked": "" ?>> Laki-laki</label>
                <label><input type="radio" name="jenis_kelamin" value="perempuan" <?php echo ($jk == 'perempuan') ? "checked": "" ?>> Perempuan</label>
            </p>
            <p>
                <label for="agama">Agama: </label>
                <?php $agama = $siswa['agama']; ?>
                <select name="agama">
                    <option <?php echo ($agama == 'Islam') ? "selected": "" ?>>Islam</option>
                    <option <?php echo ($agama == 'Kristen') ? "selected": "" ?>>Kristen</option>
                    <option <?php echo ($agama == 'Hindu') ? "selected": "" ?>>Hindu</option>
                    <option <?php echo ($agama == 'Budha') ? "selected": "" ?>>Budha</option>
                    <option <?php echo ($agama == 'Atheis') ? "selected": "" ?>>Atheis</option>
                </select>
            </p>
            <p>
                <label for="sekolah_asal">Sekolah Asal: </label>
                <input type="text" name="sekolah_asal" placeholder="nama sekolah" value="<?php echo $siswa['sekolah_asal'] ?>" />
            </p>

            <!-- Dropdown Nama Karyawan -->
            <p>
                <label for="id_karyawan">Nama Karyawan: </label>
                <select name="id_karyawan">
                    <?php
                    // Ambil data karyawan dari database
                    $karyawan_sql = "SELECT id, nama FROM karyawan";
                    $karyawan_query = mysqli_query($db, $karyawan_sql);

                    while ($karyawan = mysqli_fetch_array($karyawan_query)) {
                        // Jika id_karyawan pada siswa cocok, beri atribut 'selected'
                        $selected = ($siswa['id_karyawan'] == $karyawan['id']) ? "selected" : "";
                        echo "<option value='".$karyawan['id']."' $selected>".$karyawan['nama']."</option>";
                    }
                    ?>
                </select>
            </p>

            <p>
                <input type="submit" value="Simpan" name="simpan" />
            </p>

        </fieldset>

    </form>

</body>
</html>


list-karyawan.php
<?php include("config.php"); ?>

<!DOCTYPE html>
<html>
<head>
    <title>List Karyawan | SMK Coding</title>
</head>

<body>
    <style>
        /* General Reset */
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-color: #f4f4f9;
        color: #333;
    }

    /* Header Styling */
    header {
        background-color: #007BFF;
        color: white;
        padding: 20px;
        text-align: center;
        border-bottom: 3px solid #0056b3;
    }

    header h3 {
        margin: 0;
        font-size: 1.5em;
    }

    /* Table Styling */
    table {
        width: 80%;
        margin: 20px auto;
        border-collapse: collapse;
        background: #ffffff;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    table thead tr {
        background-color: #007BFF;
        color: white;
        text-align: left;
    }

    table th,
    table td {
        padding: 10px;
        text-align: left;
        border: 1px solid #ddd;
        font-size: 0.95em;
    }

    table tbody tr:nth-child(even) {
        background-color: #f9f9f9;
    }

    table tbody tr:hover {
        background-color: #f1f1f1;
    }

    /* Paragraph Styling */
    p {
        text-align: center;
        font-size: 1em;
        margin-top: 10px;
    }

    /* Responsive Design */
    @media (max-width: 768px) {
        table {
            width: 100%;
        }

        th,
        td {
            font-size: 0.85em;
        }
    }
    </style>
    <header>
        <h3>List Karyawan</h3>
    </header>

    <br>

    <table border="1">
    <thead>
        <tr>
            <th>No</th>
            <th>Nama</th>
            <th>Email</th>
            <th>No.HP</th>
        </tr>
    </thead>
    <tbody>

        <?php
        $sql = "SELECT * FROM karyawan";
        $query = mysqli_query($db, $sql);

        while($karyawan = mysqli_fetch_array($query)){
            echo "<tr>";

            echo "<td>".$karyawan['id']."</td>";
            echo "<td>".$karyawan['nama']."</td>";
            echo "<td>".$karyawan['email']."</td>";
            echo "<td>".$karyawan['no_hp']."</td>";
           
            echo "</tr>";
        }
        ?>

    </tbody>
    </table>

    <p>Total: <?php echo mysqli_num_rows($query) ?></p>

    </body>
</html>

proses-pendaftaran.php
<?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'];
    $karyawan = $_POST['karyawan'];
    $id_karyawan = $_POST['karyawan'];


    if($karyawan == 'Heri Senbud'){
        $id_karyawan == 1;
    }elseif($karyawan == 'Sukamti'){
        $id_karyawan == 2;
    }elseif($karyawan == 'Roni Toni'){
        $id_karyawan == 3;
    }

    // buat query
    $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal, id_karyawan) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah', '$id_karyawan')";
    $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
<?php include("config.php"); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Pendaftaran Siswa Baru | SMK Coding</title>
</head>

<body>
<style>
        body, h3, table, th, td, a, p {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    }

    /* Body style */
    body {
        background-color: #f9f9f9;
        color: #333;
        padding: 20px;
    }

    /* Header style */
    header {
        background-color: #007acc;
        color: #fff;
        text-align: center;
        padding: 15px 0;
        border-radius: 10px;
        margin-bottom: 20px;
    }

    header h3 {
        font-size: 1.5em;
    }

    /* Navigation link style */
    nav a {
        display: inline-block;
        padding: 10px 20px;
        background-color: #28a745;
        color: #fff;
        border-radius: 5px;
        text-decoration: none;
        margin-bottom: 20px;
    }

    nav a:hover {
        background-color: #218838;
    }

    /* Table style */
    table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 10px;
        background-color: #fff;
        box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
    }

    th, td {
        border: 1px solid #ddd;
        padding: 10px;
        text-align: left;
    }

    th {
        background-color: #007acc;
        color: #fff;
        text-transform: uppercase;
    }

    tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    tr:hover {
        background-color: #f1f8ff;
    }

    /* Action links style */
    a {
        color: #007acc;
        text-decoration: none;
        font-weight: bold;
    }

    a:hover {
        color: #005fa3;
    }

    /* Footer style */
    p {
        margin-top: 10px;
        font-size: 14px;
        text-align: center;
        color: #555;
    }
    </style>
    <header>
        <h3>Siswa yang sudah mendaftar</h3>
    </header>

    <nav>
        <a href="form-daftar.php">[+] Tambah Baru</a>
    </nav>

    <br>

    <table border="1">
    <thead>
        <tr>
            <th>No</th>
            <th>Nama</th>
            <th>Alamat</th>
            <th>Jenis Kelamin</th>
            <th>Agama</th>
            <th>Sekolah Asal</th>
            <th>Nama Pegawai</th>
            <th>Tindakan</th>
        </tr>
    </thead>
    <tbody>

        <?php
        $sql = "SELECT calon_siswa.*, karyawan.nama nama_pegawai
                FROM calon_siswa
                JOIN karyawan ON calon_siswa.id_karyawan = karyawan.id";
        $query = mysqli_query($db, $sql);

        while($siswa = mysqli_fetch_array($query)){
            echo "<tr>";

            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>".$siswa['nama_pegawai'];

            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>

    <p>Total: <?php echo mysqli_num_rows($query) ?></p>

    </body>
</html>
proses-edit.php
<?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'];
    $jk = $_POST['jenis_kelamin'];
    $agama = $_POST['agama'];
    $sekolah = $_POST['sekolah_asal'];

    // buat query update
    $sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jk', 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...");
}

?>
proses-pendaftaran.php
<?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'];
    $karyawan = $_POST['karyawan'];
    $id_karyawan = $_POST['karyawan'];


    if($karyawan == 'Heri Senbud'){
        $id_karyawan == 1;
    }elseif($karyawan == 'Sukamti'){
        $id_karyawan == 2;
    }elseif($karyawan == 'Roni Toni'){
        $id_karyawan == 3;
    }

    // buat query
    $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal, id_karyawan) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah', '$id_karyawan')";
    $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...");
}

?>

Komentar

Postingan populer dari blog ini

Tugas 2 PBO : Konsep OOP

Tugas Pertemuan 14 PBO

Tugas Pertemuan 10 PBO