-
Notifications
You must be signed in to change notification settings - Fork 0
/
editdatajurusan.php
162 lines (140 loc) · 5.88 KB
/
editdatajurusan.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
<?php include 'header.php';
include 'koneksi.php';
if(isset($_GET['id_jurusan'])){
$id_jurusan = $_GET['id_jurusan'];
$exec = mysqli_query($conn, "DELETE FROM jurusan WHERE id_jurusan='$id_jurusan'");
if($exec){
echo "<script>alert('data jurusan berhasil dihapus');
document.location = 'editdatajurusan.php';
</script>";
}
else{
echo "<script>alert('data jurusan gagal dihapus');
document.location = 'editdatajurusan.php';
</script>";
}
}
?>
<!-- button triger -->
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#exampleModal">Tambah Data</button>
<!-- button triger -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Data jurusan</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>No</th>
<th>Nama Jurusan</th>
<th>Aksi</th>
</tr>
</thead>
<?php
$no = 1;
$query = "SELECT * FROM jurusan";
$exec = mysqli_query($conn,$query);
while($res = mysqli_fetch_assoc($exec)):
?>
<tbody>
<tr>
<td><?= $no++ ?></td>
<td><?= $res['nama_jurusan'] ?></td>
<td>
<a href="editdatajurusan.php?id_jurusan=<?= $res['id_jurusan']?>" class="btn btn-sm btn-danger" onclick='return confirm("Apakah yakin ingin menghapus data?")'>Hapus</a>
<a href="#" class="view_data btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#myModal" id="
<?php
echo $res['id_jurusan'];
?>">Edit</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Data Jurusan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">x</button>
</div>
<div class="modal-body">
<form action="" method="POST">
<input type="text" name="nama_jurusan" placeholder="Nama jurusan" class="form-control mb-2">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="Submit" name="simpan" class="btn btn-primary">Simpan</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Data Jurusan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close">x</button>
</div>
<div class="modal-body" id="datajurusan">
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['simpan'])){
$nama_jurusan = htmlentities(strip_tags($_POST['nama_jurusan']));
$query = "INSERT INTO jurusan(nama_jurusan) VALUES ('$nama_jurusan')";
$exec = mysqli_query($conn, $query);
if($exec){
echo "<script>alert('data jurusan berhasil disimpan');
document.location = 'editdatajurusan.php';
</script>";
}
else{
echo "<script>alert('data jurusan gagal disimpan');
document.location = 'editdatajurusan.php';
</script>";
}
}
?>
<?php include 'footer.php'; ?>
<script>
$('.view_data').click(function(){
var id_jurusan = $(this).attr('id');
$.ajax({
url:'view.php',
method:'post',
data:{id_jurusan:id_jurusan},
success:function(data){
$('#datajurusan').html(data);
$('#myModal').modal('show');
}
})
})
</script>
<?php
if(isset($_POST['edit'])){
$id_jurusan = $_POST['id_jurusan'];
$nama_jurusan = htmlentities(strip_tags(strtoupper($_POST['nama_jurusan'])));
$query = "UPDATE jurusan SET nama_jurusan = '$nama_jurusan' WHERE id_jurusan = '$id_jurusan'";
$exec = mysqli_query($conn,$query);
if($exec){
echo "<script>alert('data jurusan berhasil diubah');
document.location = 'editdatajurusan.php';
</script>";
}
else{
echo "<script>alert('data jurusan gagal diubah');
document.location = 'editdatajurusan.php';
</script>";
}
}
?>