-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_skills.php
127 lines (115 loc) · 4.45 KB
/
manage_skills.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
// Database connection (modify with your database details)
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "portofolio";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert new skill
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['skillName'])) {
$skillName = $_POST['skillName'];
$skillLevel = $_POST['skillLevel'];
if (isset($_POST['skillId'])) {
$skillId = $_POST['skillId'];
$sql = "UPDATE skills SET name='$skillName', level='$skillLevel' WHERE id='$skillId'";
} else {
$sql = "INSERT INTO skills (name, level) VALUES ('$skillName', '$skillLevel')";
}
if ($conn->query($sql) === TRUE) {
echo "Data skill berhasil disimpan";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// Delete skill
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['deleteId'])) {
$skillId = $_GET['deleteId'];
$sql = "DELETE FROM skills WHERE id='$skillId'";
if ($conn->query($sql) === TRUE) {
echo "Data skill berhasil dihapus";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// Fetch skills
$skills = [];
$sql = "SELECT * FROM skills";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$skills[] = $row;
}
} else {
echo "0 results";
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Skills</title>
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1>Manage Skills</h1>
<form action="" method="post">
<div class="form-group">
<label for="skillName">Skill Name</label>
<input type="text" id="skillName" name="skillName" class="form-control" required>
</div>
<div class="form-group">
<label for="skillLevel">Skill Level</label>
<input type="text" id="skillLevel" name="skillLevel" class="form-control" required>
</div>
<input type="hidden" id="skillId" name="skillId" value="">
<button type="submit" class="btn btn-primary">Simpan</button>
<button type="button" class="btn btn-secondary" onclick="window.location.href='admin_dashboard.php';">Kembali</button>
</form>
<hr>
<h2>Existing Skills</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Level</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($skills as $skill): ?>
<tr>
<td><?php echo htmlspecialchars($skill['name']); ?></td>
<td><?php echo htmlspecialchars($skill['level']); ?></td>
<td>
<button type="button" class="btn btn-primary btn-sm" onclick="editSkill(<?php echo $skill['id']; ?>, '<?php echo $skill['name']; ?>', '<?php echo $skill['level']; ?>')">Edit</button>
<a href="?deleteId=<?php echo $skill['id']; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Anda yakin ingin menghapus data ini?')">Hapus</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script>
function editSkill(id, name, level) {
document.getElementById('skillId').value = id;
document.getElementById('skillName').value = name;
document.getElementById('skillLevel').value = level;
}
</script>
</body>
</html>