-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
52 lines (43 loc) · 1.26 KB
/
edit.php
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
<?php
include('config.php');
include('fungsi.php');
// mendapatkan data edit
if(isset($_GET['jenis']) && isset($_GET['id'])) {
$id = $_GET['id'];
$jenis = $_GET['jenis'];
// hapus record
$query = "SELECT nama FROM $jenis WHERE id=$id";
$result = mysqli_query($koneksi, $query);
while ($row = mysqli_fetch_array($result)) {
$nama = $row['nama'];
}
}
if (isset($_POST['update'])) {
$id = $_POST['id'];
$jenis = $_POST['jenis'];
$nama = $_POST['nama'];
$query = "UPDATE $jenis SET nama='$nama' WHERE id=$id";
$result = mysqli_query($koneksi, $query);
if (!$result) {
echo "Update gagal";
exit();
} else {
header('Location: '.$jenis.'.php');
exit();
}
}
include('navbar.php');
?>
<section class="content container mt-5 justify-content-center text-center">
<h2>Edit <?php echo $jenis?></h2>
<form class="ui form" method="post" action="edit.php">
<div class="inline field">
<label>Nama <?php echo $jenis ?> : </label>
<input type="text" name="nama" value="<?php echo $nama?>">
<input type="hidden" name="id" value="<?php echo $id?>">
<input type="hidden" name="jenis" value="<?php echo $jenis?>">
</div>
<br>
<input class="ui green button" type="submit" name="update" value="UPDATE">
</form>
</section>