-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
70 lines (66 loc) · 2.52 KB
/
Copy pathcreate.php
File metadata and controls
70 lines (66 loc) · 2.52 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
<?php
require_once 'config/database.php';
$pesan = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nama_barang = trim($_POST['nama_barang'] ?? '');
$kategori = trim($_POST['kategori'] ?? '');
$jumlah = trim($_POST['jumlah'] ?? '');
$harga = trim($_POST['harga'] ?? '');
$lokasi = trim($_POST['lokasi'] ?? '');
if (!empty($nama_barang) && !empty($kategori) && !empty($jumlah) && !empty($harga)) {
$stmt = $pdo->prepare("INSERT INTO barang (nama_barang, kategori, jumlah, harga, lokasi) VALUES (:nama_barang, :kategori, :jumlah, :harga, :lokasi)");
$stmt->execute([
':nama_barang' => $nama_barang,
':kategori' => $kategori,
':jumlah' => (int)$jumlah,
':harga' => (float)$harga,
':lokasi' => $lokasi,
]);
header("Location: index.php?pesan=tambah_sukses");
exit;
} else {
$pesan = "Semua field wajib diisi!";
}
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tambah Barang</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5" style="max-width: 600px;">
<h2>+ Tambah Barang Baru</h2>
<?php if ($pesan): ?>
<div class="alert alert-danger"><?= $pesan ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label">Nama Barang</label>
<input type="text" name="nama_barang" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Kategori</label>
<input type="text" name="kategori" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Jumlah</label>
<input type="number" name="jumlah" class="form-control" min="0" required>
</div>
<div class="mb-3">
<label class="form-label">Harga</label>
<input type="number" name="harga" class="form-control" min="0" step="any" required>
</div>
<div class="mb-3">
<label class="form-label">Lokasi</label>
<input type="text" name="lokasi" class="form-control">
</div>
<button type="submit" class="btn btn-success">Simpan</button>
<a href="index.php" class="btn btn-secondary">← Kembali</a>
</form>
</div>
</body>
</html>