-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedit-harga.php
127 lines (104 loc) · 3.47 KB
/
edit-harga.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
<?php
session_start();
include 'connect-db.php';
include 'functions/functions.php';
// cek apakah sudah login sebagai agen
cekAgen();
// mengambil id agen di session
$idAgen = $_SESSION["agen"];
// mengambil data harga pada db
$cuci = mysqli_query($connect, "SELECT * FROM harga WHERE id_agen = '$idAgen' AND jenis = 'cuci'");
$cuci = mysqli_fetch_assoc($cuci);
$setrika = mysqli_query($connect, "SELECT * FROM harga WHERE id_agen = '$idAgen' AND jenis = 'setrika'");
$setrika = mysqli_fetch_assoc($setrika);
$komplit = mysqli_query($connect, "SELECT * FROM harga WHERE id_agen = '$idAgen' AND jenis = 'komplit'");
$komplit = mysqli_fetch_assoc($komplit);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include "headtags.html"; ?>
<title>Ubah Data Harga</title>
</head>
<body>
<!-- header -->
<?php include 'header.php'; ?>
<!-- end header -->
<!-- body -->
<div class="container">
<h3 class="header light center">Data Harga</h3>
<form action="" method="post">
<div class="input field">
<label for="cuci">Cuci</label>
<input type="text" id="cuci" name="cuci" value="<?= $cuci['harga'] ?>">
</div>
<div class="input field">
<label for="setrika">Setrika</label>
<input type="text" id="setrika" name="setrika" value="<?= $setrika['harga'] ?>">
</div>
<div class="input field">
<label for="komplit">Cuci + Setrika</label><input type="text" id="komplit" name="komplit" value="<?= $komplit['harga'] ?>">
</div>
<div class="input field center">
<button class="btn-large blue darken-2" type="submit" name="simpan">Simpan Data</button>
</div>
</form>
</div>
<!-- end body -->
<!-- footer -->
<?php include "footer.php" ?>
<!-- end footer -->
</body>
</html>
<?php
// fungsi mengubah harga
function ubahHarga($data){
global $connect, $idAgen;
$hargaCuci = htmlspecialchars($data["cuci"]);
$hargaSetrika = htmlspecialchars($data["setrika"]);
$hargaKomplit = htmlspecialchars($data["komplit"]);
validasiHarga($hargaCuci);
validasiHarga($hargaSetrika);
validasiHarga($hargaKomplit);
$query1 = "UPDATE harga SET
harga = $hargaCuci
WHERE jenis = 'cuci' AND id_agen = $idAgen
";
$query2 = "UPDATE harga SET
harga = $hargaSetrika
WHERE jenis = 'setrika' AND id_agen = $idAgen
";
$query3 = "UPDATE harga SET
harga = $hargaKomplit
WHERE jenis = 'komplit' AND id_agen = $idAgen
";
mysqli_query($connect,$query1);
$hasil1 = mysqli_affected_rows($connect);
mysqli_query($connect,$query2);
$hasil2 = mysqli_affected_rows($connect);
mysqli_query($connect,$query3);
$hasil3 = mysqli_affected_rows($connect);
return $hasil1+$hasil2+$hasil3;
}
// jika user menekan tombol simpan harga
if (isset($_POST["simpan"])) {
if ( ubahHarga($_POST) > 0) {
echo "
<script>
Swal.fire('Data Berhasil Di Update','','success').then(function() {
window.location = 'edit-harga.php';
});
</script>
";
}else {
echo "
<script>
Swal.fire('Data Gagal Di Update','','error');
</script>
";
mysqli_error($connect);
}
}
?>