-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
82 lines (64 loc) · 2.32 KB
/
edit.php
File metadata and controls
82 lines (64 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<title>KEAMANAN SISTEM</title>
</head>
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
<body>
<div class="container col-md-6 mt-4">
<h1>Table Mahasiswa</h1>
<div class="card">
<div class="card-header bg-success text-white ">
Edit Mahasiswa
</div>
<div class="card-body">
<?php
include('koneksi.php');
$id = $_GET['id']; //mengambil id barang yang ingin diubah
//menampilkan barang berdasarkan id
$data = mysqli_query($koneksi, "select * from mahasiswa where id = '$id'");
$row = mysqli_fetch_assoc($data);
?>
<form action="" method="post" role="form">
<div class="form-group">
<label>Nama</label>
<!-- menampilkan nama barang -->
<input type="text" name="nama" required="" class="form-control" value="<?= $row['nama']; ?>">
<!-- ini digunakan untuk menampung id yang ingin diubah -->
<input type="hidden" name="id" required="" value="<?= $row['id']; ?>">
</div>
<div class="form-group">
<label>NIM</label>
<input type="text" name="nim" class="form-control" value="<?= $row['nim']; ?>">
</div>
<div class="form-group">
<label>Alamat</label>
<textarea class="form-control" name="alamat"><?= $row['alamat']; ?></textarea>
</div>
<div class="form-group">
<label>Gambar</label>
<input type="file" name="gambar" required="" class="form-control">
</div>
<button type="submit" class="btn btn-primary" name="submit" value="simpan">update data</button>
</form>
<?php
//jika klik tombol submit maka akan melakukan perubahan
if (isset($_POST['submit'])) {
$id = $_POST['id'];
$nama = $_POST['nama'];
$nim = $_POST['nim'];
$alamat = $_POST['alamat'];
$gambar = $_POST['gambar'];
//query mengubah barang
mysqli_query($koneksi, "update mahasiswa set nama='$nama', nim='$nim', alamat='$alamat', gambar='$gambar' where id ='$id'") or die(mysqli_error($koneksi));
//redirect ke halaman index.php
echo "<script>alert('data berhasil diupdate.');window.location='home.php';</script>";
}
?>
</div>
</div>
</div>
<script type="text/javascript" src="assets/js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
</body>
</html>