-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_alternative.php
67 lines (60 loc) · 1.64 KB
/
process_alternative.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
<?php
require 'alternatives.php';
// Proses tambah alternatif
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['mode']) && $_GET['mode'] === 'add') {
$name = $_POST['name'];
$values = array(
$_POST['value1'],
$_POST['value2'],
$_POST['value3'],
$_POST['value4'],
$_POST['value5']
);
// Menyimpan data alternatif
$result = createAlternative($name, $values);
if ($result) {
echo "Alternatif berhasil ditambahkan.";
} else {
echo "Gagal menambahkan alternatif.";
}
}
// Proses update alternatif
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['mode']) && $_GET['mode'] === 'update') {
$id = $_GET['id'];
$name = $_POST['name'];
$values = array(
$_POST['value1'],
$_POST['value2'],
$_POST['value3'],
$_POST['value4'],
$_POST['value5']
);
// Mengupdate data alternatif
$result = updateAlternative($id, $name, $values);
if ($result) {
echo "Alternatif berhasil diupdate.";
} else {
echo "Gagal mengupdate alternatif.";
}
}
// Proses tambah alternatif (tanpa mode)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_GET['mode'])) {
$name = $_POST['name'];
$values = array(
$_POST['value1'],
$_POST['value2'],
$_POST['value3'],
$_POST['value4'],
$_POST['value5']
);
// Menyimpan data alternatif
$result = createAlternative($name, $values);
if ($result) {
echo "Alternatif berhasil ditambahkan.";
} else {
echo "Gagal menambahkan alternatif.";
}
}
?>
<br>
<a href="alternatif.php">Kembali</a>