<a href="index.php">Show Data</a>
<br><br>

<?php
include 'config.php';
$a=mysqli_query($conn,"SELECT * FROM dosen WHERE nidn='$_GET[nidn]'");
$b=mysqli_fetch_array($a,MYSQLI_ASSOC)
?>

<form method="post">
  <table>
    <tr>
      <td>NIDN</td>
      <td><input type="text" name="nidn" placeholder="Masukkan NIDN" value="<?= $b['nidn'] ?>"></td>
    </tr>
    <tr>
      <td>Nama</td>
      <td><input type="text" name="nama" placeholder="Masukkan Nama" value="<?= $b['nama']; ?>"></td>
    </tr>
    <tr>
      <td>Jabatan</td>
      <td><input type="text" name="jabatan" placeholder="Masukkan Jabatan" value="<?= $b['jabatan']; ?>"></td>
    </tr>
    <tr>
      <td>Program Studi</td>
      <td>
        <select name="program_studi" >
          <option value="D3 Teknologi Informasi" <?php if($b['program_studi'] == "D3 Teknologi Informasi") echo "selected"; ?>>D3 Teknologi Informasi</option>
          <option value="D3 Teknologi Komputer" <?php if($b['program_studi'] == "D3 Teknologi Komputer") echo "selected"; ?>>D3 Teknologi Komputer</option>
          <option value="D4 Teknologi Rekayasa Perangkat Lunak" <?php if($b['program_studi'] == "D4 Teknologi Rekayasa Perangkat Lunak") echo "selected"; ?>>D4 Teknologi Rekayasa Perangkat Lunak</option>
          <option value="S1 Informatika"<?php if($b['program_studi'] == "S1 Informatika") echo "selected"; ?>>S1 Informatika</option>
          <option value="S1 Sistem Informasi" <?php if($b['program_studi'] == "S1 Sistem Informasi") echo "selected"; ?>>S1 Sistem Informasi</option>
          <option value="S1 Teknik Elektro" <?php if($b['program_studi'] == "S1 Teknik Elektro") echo "selected"; ?>>S1 Teknik Elektro</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>Golongan</td>
      <td><input type="text" name="golongan" placeholder="Masukkan golongan" value="<?= $b['golongan']; ?>"></td>
    </tr>
    <tr>
      <td>Pendidikan</td>
      <td><input type="text" name="pendidikan" placeholder="Masukkan Pendidikan" value="<?= $b['pendidikan']; ?>"></td>
    </tr>
    <tr>
      <td>Tahun Mulai S1</td>
      <td><input type="date" name="mulai_s1" value="<?= $b['mulai_s1']; ?>"></td>
    </tr>
    <tr>
      <td>Tahun Lulus S1</td>
      <td><input type="date" name="lulus_s1" value="<?= $b['lulus_s1']; ?>"></td>
    </tr>
    <tr>
      <td>Tahun Mulai S2</td>
      <td><input type="date" name="mulai_s2" value="<?= $b['mulai_s2']; ?>"></td>
    </tr>
    <tr>
      <td>Tahun Lulus S2</td>
      <td><input type="date" name="lulus_s2" value="<?= $b['lulus_s2']; ?>"></td>
    </tr>
    <tr>
      <td>Username</td>
      <td><input type="username" name="username" placeholder="Masukkan Username" value="<?= $b['username']; ?>"></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input type="password" name="password" placeholder="Masukkan Password" value="<?= $b['password']; ?>"></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input type="email" name="email" placeholder="Masukkan email" value="<?= $b['email']; ?>"></td>
    </tr>
    <tr>
      <td><input type="submit" name="update" value="Update"></td>
      <td><input type="reset" name="reset" value="Cancel"></td>
    </tr>
  </table>
</form>

<?php
if(isset($_POST['update']))
{
  include 'config.php';

  $nidn = $_POST['nidn'];
  $nama = $_POST['nama'];
  $jabatan = $_POST['jabatan'];
  $program_studi = $_POST['program_studi'];
  $golongan = $_POST['golongan'];
  $pendidikan = $_POST['pendidikan'];
  $mulai_s1 = $_POST['mulai_s1'];
  $lulus_s1 = $_POST['lulus_s1'];
  $mulai_s2 = $_POST['mulai_s2'];
  $lulus_s2 = $_POST['lulus_s2'];
  $username = $_POST['username'];
  $password = $_POST['password'];
  $email = $_POST['email'];

  $sql="UPDATE dosen SET nidn='$nidn', nama='$nama', jabatan='$jabatan', program_studi='$program_studi', golongan='$golongan', pendidikan='$pendidikan', mulai_s1='$mulai_s1', lulus_s1='$lulus_s1', mulai_s2='$mulai_s2', lulus_s2='$lulus_s2', username='$username', password='$password', email='$email' WHERE nidn='$_GET[nidn]'";
  if($conn->query($sql) === false)
  { // Jika gagal meng-insert data tampilkan pesan dibawah 'Perintah SQL Salah'
    trigger_error('Wrong SQL Command: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
  }  
  else 
  { // Jika berhasil alihkan ke halaman tampil.php
    echo "<script>alert('Update Success!')</script>";
  	echo "<meta http-equiv=refresh content=\"0; url=index.php\">";
  }
}

?>   