Skip to content

Commit b84c848

Browse files
committed
feat: add update-db
1 parent 0c9c739 commit b84c848

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="col col-4 mx-auto">
88
<div class="card shadow">
99
<div class="card-header">
10-
<h4>Form Pendaftaran</h4>
10+
<h4 class="text-center">Form Pendaftaran</h4>
1111
</div>
1212
<div class="card-body">
1313
<form action="process-form.php" method="post">

functions/functions.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function All($tbname) {
1717

1818
function byNRP($id) {
1919
global $conn;
20-
$qry = "SELECT * FROM tugas6pweb WHERE nrp = " . $id;
20+
$qry = "SELECT * FROM tugas6pweb WHERE nrp = '$id'";
2121
$res = pg_query($conn,$qry);
2222

2323
if(!$res) {
@@ -45,7 +45,25 @@ function insert($data) {
4545

4646
function delete($id){
4747
global $conn;
48-
$qry = "DELETE FROM tugas6pweb WHERE nrp = '" . $id . "'";
48+
$qry = "DELETE FROM tugas6pweb WHERE nrp = '$id'";
4949
$res = pg_query($conn,$qry);
5050
return pg_affected_rows($res);
51-
}
51+
}
52+
53+
function update($data) {
54+
global $conn;
55+
$nname = $data['nama'];
56+
$dnrp = $data['nrp'];
57+
$ndpt = $data['departemen'];
58+
$nasal = $data['asal'];
59+
$ntanggal = $data['tanggal'];
60+
$qry = "UPDATE tugas6pweb SET
61+
nama = '$nname',
62+
departemen = '$ndpt',
63+
asal = '$nasal',
64+
mining_at = '$ntanggal'
65+
WHERE nrp = '$dnrp'";
66+
$res = pg_query($conn,$qry);
67+
return pg_affected_rows($res);
68+
}
69+
?>

process-update.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
require 'includes/header.php';
3+
if(isset($_POST['update']) && update($_POST)) {
4+
return header('Location: index.php');
5+
}
6+
?>

update.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
require 'includes/header.php';
3+
if(isset($_GET['nrp'])) {
4+
$data = byNRP($_GET['nrp']);
5+
}
6+
?>
7+
8+
<div class="container my-4">
9+
<div class="row">
10+
<div class="col col-4 mx-auto">
11+
<div class="card shadow">
12+
<div class="card-header">
13+
<h4 class="text-center">Update Form</h4>
14+
</div>
15+
<div class="card-body">
16+
<form action="process-update.php" method="post">
17+
<div class="form-group">
18+
<label for="">Nama</label>
19+
<input type="text" name="nama" class="form-control" value="<?= $data['nama'] ?>">
20+
</div>
21+
<input type="hidden" name="nrp" value="<?= $data['nrp'] ?>">
22+
<div class="form-group">
23+
<label for="">Departemen</label>
24+
<input type="text" name="departemen" class="form-control" value="<?= $data['departemen'] ?>">
25+
</div>
26+
<div class="form-group">
27+
<label for="">Asal</label>
28+
<input type="text" name="asal" class="form-control" value="<?= $data['asal'] ?>">
29+
</div>
30+
<div class="form-group">
31+
<label for="">Tanggal</label>
32+
<input type="text" name="tanggal" class="form-control" value="<?= $data['mining_at'] ?>">
33+
</div>
34+
</div>
35+
<div class="card-footer">
36+
<div class="d-flex justify-content-around">
37+
<a href="index.php" class="btn btn-danger btn-sm">Batal</a>
38+
<button type="submit" name="update" class="btn btn-primary btn-sm">Update</button>
39+
</form>
40+
</div>
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
</div>

0 commit comments

Comments
 (0)