mnaufaldillah

form edit tugas php

Dec 6th, 2021
513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     include('config.php');
  3.  
  4.     //ambil data dari url
  5.     $id = $_GET['id'];
  6.  
  7.     $sql = 'SELECT * FROM calon_siswa WHERE id = '.$id;
  8.     $query = mysqli_query($db_connection, $sql);
  9.     $siswa = mysqli_fetch_assoc($query);
  10.  
  11.     if (mysqli_num_rows($query) < 1) {
  12.         header('Location: list-siswa.php');
  13.      }
  14. ?>
  15.  
  16. <!DOCTYPE html>
  17. <html>
  18. <head>
  19.     <title>Formulir Edit</title>
  20.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  21. </head>
  22. <body>
  23.     <header>
  24.         <h3>Formulir Edit</h3>
  25.     </header>
  26.  
  27.     <form method="post" action="proses-edit.php">
  28.         <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>">
  29.         <p>
  30.             <label class="form-label">Nama: </label>
  31.             <input type="type" name="nama" placeholder="nama lengkap" class="form-control" value="<?php echo $siswa['nama'] ?>">
  32.         </p>
  33.         <p>
  34.             <label class="form-label">Alamat: </label>
  35.             <textarea name="alamat" class="form-control"><?php echo $siswa['alamat'] ?></textarea>
  36.         </p>
  37.         <p>
  38.             <label>Jenis Kelamin: </label>
  39.             <select name="jenis_kelamin">
  40.                 <option value="laki-laki" <?php echo ($siswa['jenis_kelamin'] == 'laki-laki') ? 'selected' : '' ?>>laki-laki</option>
  41.                 <option value="perempuan" <?php echo ($siswa['jenis_kelamin'] == 'perempuan') ? 'selected' : '' ?>>perempuan</option>
  42.             </select>
  43.         </p>
  44.         <p>
  45.             <label>Agama: </label>
  46.             <select name="agama">
  47.                 <option <?php echo ($siswa['agama'] == 'islam') ? 'selected' : '' ?> value="islam">islam</option>
  48.                 <option <?php echo ($siswa['agama'] == 'kristen') ? 'selected' : '' ?> value="kristen">kristen</option>
  49.                 <option <?php echo ($siswa['agama'] == 'katolik') ? 'selected' : '' ?> value="katolik">katolik</option>
  50.                 <option <?php echo ($siswa['agama'] == 'hindu') ? 'selected' : '' ?> value="hindu">hindu</option>
  51.                 <option <?php echo ($siswa['agama'] == 'buddha') ? 'selected' : '' ?> value="buddha">buddha</option>
  52.                 <option <?php echo ($siswa['agama'] == 'konghucu') ? 'selected' : '' ?> value="konghucu">konghucu</option>
  53.             </select>
  54.         </p>
  55.         <p>
  56.             <label>Asal Sekolah: </label>
  57.             <input type="type" name="sekolah_asal" placeholder="sekolah asal" class="form-control" value="<?php echo $siswa['sekolah_asal'] ?>">
  58.         </p>
  59.         <p>
  60.             <button type="submit" class="btn btn-success">Perbarui</button>
  61.         </p>
  62.     </form>
  63. </body>
  64. </html>
RAW Paste Data