-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_barang.php
201 lines (168 loc) · 5.93 KB
/
form_barang.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
session_start();
if (isset($_POST['logout'])) {
session_destroy();
header("location:login.php?status=logout");
}
if (!isset($_SESSION['user_login'])) {
header("location:login.php");
}
include('connect.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>FORM - BARANG</title>
<link rel="shortcut icon" href="resource/icon.png" />
<link rel='stylesheet' href='resource/bootstrap.min.css'>
</head>
<body>
<STYLE>body{
font-family: 'Trebuchet MS', serif;
}</STYLE>
<?php
include('resource/navbar.php');
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$idErr = $namabarangErr = $jumlahErr = $tahunbeliErr = $ownerErr = $lokasiErr = "";
$id = $namabarang = $jumlah = $tahunbeli = $owner = $lokasi = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["namabarang"])) {
$namabarangErr = "Nama Barang harus di isi!";
}else {
$namabarang = test_input($_POST["namabarang"]);
$namabarangErr = "";
}
if (empty($_POST["jumlah"])) {
$jumlahErr = "Jumlah harus di isi!";
} else {
$jumlah = test_input($_POST["jumlah"]);
$jumlahErr = "";
if (!preg_match("/^[0-9]*$/",$jumlah)) {
$jumlahErr = "Isikan dengan angka!";
}
}
if (empty($_POST["tahunbeli"])) {
$tahunbeliErr = "Tahun Beli harus di isi!";
}else {
$tahunbeli = test_input($_POST["tahunbeli"]);
$tahunbeliErr = "";
}
if (empty($_POST["owner"])) {
$ownerErr = "Owner harus di isi!";
}else {
$owner = test_input($_POST["owner"]);
$ownerErr = "";
}
if (empty($_POST["lokasi"])) {
$lokasiErr = "Lokasi harus di isi!";
}else {
$lokasi = test_input($_POST["lokasi"]);
$lokasiErr = "";
}
$baca_id = mysqli_query($conn, "select max(id) from barang;");
$b_id = mysqli_fetch_assoc($baca_id);
$id = (int)$b_id['max(id)']+1;
$sql = "insert into barang VALUES( $id,'".$_POST['namabarang']."','".$_POST['jumlah']."',0,0,0,'".$_POST['tahunbeli']."','".$_POST['owner']."','".$_POST['lokasi']."')";
if($namabarangErr == "" && $jumlahErr == "" && $tahunbeliErr == "" && $ownerErr == "" && $lokasiErr == "")
{
// echo "ehllo";
if (mysqli_query($conn, $sql)) {
echo"<div class='alert alert-success text-center' role='alert'>Sukses Memasukan data</div>";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="container-fluid">
<div class="row">
<div class="col-12 text-center" style="margin-top:30px;margin-bottom:20px;">
<h2 class='display-4'>FORM BARANG</h2>
</div>
</div>
<div class="row">
<div class="col-3"></div>
<div class="col-6">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="form-group">
<label>Nama Barang:</label><span class="text-danger">* <?php echo $namabarangErr;?></span>
<input class='form-control' type="char" name="namabarang" value="<?php echo $namabarang;?>">
</div>
<div class="form-group">
<label>Jumlah :</label><span class="text-danger">* <?php echo $jumlahErr;?></span>
<input class='form-control' type="number" name="jumlah" value="<?php echo $jumlah;?>">
</div>
<div class="form-group">
<label>Tahun Beli :</label><span class="text-danger">* <?php echo $tahunbeliErr;?></span>
<input class='form-control date' type="text" name="tahunbeli" value="<?php echo $tahunbeli;?>" readonly>
</div>
<div class="form-group">
<label>Owner :</label><span class="text-danger">* <?php echo $ownerErr;?></span>
<select name="owner" id="" class='form-control' value="<?php echo $owner;?>" type="text">
<?php
$sqldata = mysqli_query($conn, "select * from owner");
while($data = mysqli_fetch_assoc($sqldata))
{
echo "<option value=",$data['id'],">",$data['owner'],"</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>Lokasi</label><span class="text-danger">* <?php echo $lokasiErr;?></span>
<select name="lokasi" id="" class='form-control' value="<?php echo $lokasi;?>" type="text">
<?php
$sqldata = mysqli_query($conn, "select * from lokasi");
while($data = mysqli_fetch_assoc($sqldata))
{
echo "<option value=",$data['id'],">",$data['lokasi'],"</option>";
}
?>
</select>
</div>
<p><span class="text-danger">* Wajib diisi!</span></p>
<input class='btn btn-primary'type="submit" name="submit" value="Masukkan Data">
</form>
</div>
</div>
</div>
<?php
// echo "<h2>Your Input:</h2>";
// echo $namabarangErr;
// echo "<br>";
// echo $jumlahErr;
// echo "<br>";
// echo $tahunbeliErr;
// echo "<br>";
// echo $ownerErr;
// echo "<br>";
// echo $lokasiErr;
?>
<script src="resource/jquery-3.3.1.slim.min.js" ></script>
<script src="resource/popper.min.js" ></script>
<script src="resource/bootstrap.min.js" ></script>
<script src="resource/bootstrap.bundle.min.js"></script>
<script type='text/javascript' src="resource/bootstrap-datepicker.min.js"></script>
<script type='text/javascript' src="resource/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="resource/bootstrap-datepicker3.css">
<script type='text/javascript'>
$('.date').datepicker({
format: "yyyy",
startView : 2,
minViewMode: 2,
autoclose: true
});
</script>
</body>
</html>