daniramadhan7

Pendaftaran-Siswa form-edit.php

Dec 6th, 2021
744
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. include("config.php");
  4.  
  5. // kalau tidak ada id di query string
  6. if( !isset($_GET['id']) ){
  7.    header('Location: list-siswa.php');
  8. }
  9.  
  10. //ambil id dari query string
  11. $id = $_GET['id'];
  12.  
  13. // buat query untuk ambil data dari database
  14. $sql = "SELECT * FROM calon_siswa WHERE id=$id";
  15. $query = mysqli_query($db, $sql);
  16. $siswa = mysqli_fetch_assoc($query);
  17.  
  18. // jika data yang di-edit tidak ditemukan
  19. if( mysqli_num_rows($query) < 1 ){
  20.    die("data tidak ditemukan...");
  21. }
  22.  
  23. ?>
  24.  
  25.  
  26. <!DOCTYPE html>
  27. <html>
  28.  
  29. <head>
  30.     <!-- Required meta tags -->
  31.     <meta charset="utf-8">
  32.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  33.  
  34.     <!-- Bootstrap CSS -->
  35.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
  36.        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  37.  
  38.     <title>Formulir Edit Siswa | SMK Coding</title>
  39. </head>
  40.  
  41. <body>
  42.     <div class="mx-auto" style="width: 50%; margin-top: 5%;">
  43.         <!-- Centered element -->
  44.         <header>
  45.             <h3>Formulir Edit Siswa</h3>
  46.         </header>
  47.         <br>
  48.  
  49.         <form action="proses-edit.php" method="POST">
  50.  
  51.             <fieldset>
  52.  
  53.                 <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />
  54.  
  55.                 <div class="mb-3">
  56.                     <label for="nama" class="form-label">Nama </label>
  57.                     <input type="text" class="form-control" id="nama" name="nama" placeholder="nama lengkap" value="<?php echo $siswa['nama'] ?>" />
  58.                 </div>
  59.                 <div class="mb-3">
  60.                     <label for="alamat" class="form-label">Alamat </label>
  61.                     <textarea name="alamat" class="form-control" id="alamat" name="alamat"><?php echo $siswa['alamat'] ?></textarea>
  62.                 </div>
  63.                 <div class="mb-3">
  64.                     <label for="jenis_kelamin" class="form-label">Jenis Kelamin </label>
  65.                     <?php $jk = $siswa['jenis_kelamin']; ?>
  66.                     <label><input type="radio" name="jenis_kelamin" value="laki-laki"
  67.                            <?php echo ($jk == 'laki-laki') ? "checked": "" ?>> Laki-laki</label>
  68.                     <label><input type="radio" name="jenis_kelamin" value="perempuan"
  69.                            <?php echo ($jk == 'perempuan') ? "checked": "" ?>> Perempuan</label>
  70.                 </div>
  71.                 <div class="mb-3">
  72.                     <label for="agama" class="form-label">Agama </label>
  73.                     <?php $agama = $siswa['agama']; ?>
  74.                     <select name="agama" class="form-control">
  75.                         <option <?php echo ($agama == 'Islam') ? "selected": "" ?>>Islam</option>
  76.                         <option <?php echo ($agama == 'Kristen') ? "selected": "" ?>>Kristen</option>
  77.                         <option <?php echo ($agama == 'Hindu') ? "selected": "" ?>>Hindu</option>
  78.                         <option <?php echo ($agama == 'Budha') ? "selected": "" ?>>Budha</option>
  79.                         <option <?php echo ($agama == 'Atheis') ? "selected": "" ?>>Atheis</option>
  80.                     </select>
  81.                 </div>
  82.                 <div class="mb-3">
  83.                     <label for="sekolah_asal" class="form-label">Sekolah Asal </label>
  84.                     <input type="text" class="form-control" name="sekolah_asal" id="sekolah_asal" placeholder="nama sekolah"
  85.                        value="<?php echo $siswa['sekolah_asal'] ?>" />
  86.                 </div>
  87.                 <div class="mb-3">
  88.                     <input type="submit"  class="btn btn-primary" value="Simpan" name="simpan" />
  89.                 </div>
  90.  
  91.             </fieldset>
  92.  
  93.  
  94.         </form>
  95.     </div>
  96. </body>
  97.  
  98. </html>
RAW Paste Data