-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarang-edit.php
85 lines (66 loc) · 2.13 KB
/
barang-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
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
83
84
85
<?php
$title = 'Edit Barang';
require_once "template/theHeader.php";
?>
<div class="level">
<div class="level-left">
<div class="level-item">
<h1 class="title is-4">Edit Barang</h1>
</div>
</div>
<div class="level-right">
<div class="level-item">
<a href="barang-show.php?id=<?= $_GET['id'] ?>" class="button is-light">Lihat</a>
</div>
<div class="level-item">
<a href="barang.php" class="button is-light">Kembali</a>
</div>
</div>
</div>
<hr>
<?php
if (isset($_POST['simpan'])) {
$fields = [
'nama_barang' => $_POST['nama'],
'harga_barang' => $_POST['harga'],
'stok_barang' => $_POST['stok'],
];
if (update('barang', $fields, 'id_barang', $_POST['id'])) {
return header('Location:barang.php');
}
hasMessage('Maaf!, tidak dapat menyimpan data.');
}
if (isset($_GET['id'])) {
$query = $conn->query(sprintf("SELECT * FROM barang WHERE id_barang = %s", $_GET['id']));
$item = $query->fetch_object();
} else {
return header('Location:barang.php');
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?= $item->id_barang; ?>">
<div class="field">
<label for="nama" class="label">Nama Barang</label>
<div class="control">
<input type="text" name="nama" id="nama" class="input" value="<?= old('nama', $item->nama_barang); ?>" required>
</div>
</div>
<div class="field">
<label for="harga" class="label">Harga</label>
<div class="control">
<input type="number" name="harga" id="harga" class="input" value="<?= old('harga', $item->harga_barang); ?>" required>
</div>
</div>
<div class="field">
<label for="stok" class="label">Stok</label>
<div class="control">
<input type="number" name="stok" id="stok" class="input" value="<?= old('stok', $item->stok_barang) ?>" required>
</div>
</div>
<div class="field">
<button name="simpan" class="button is-success">Perbarui</button>
</div>
</form>
<?php
require_once "template/theFooter.php"
?>