-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
71 lines (66 loc) · 1.77 KB
/
index.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
<?php include("server.php"); ?>
<?php $result = mysqli_query($db, "SELECT * FROM user"); ?>
<?php
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM user WHERE id=$id");
if (count(array($record)) == 1 ) {
$n = mysqli_fetch_array($record);
$nama = $n['nama'];
$kota = $n['kota'];
}
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Learn PHP7 | Simple-CRUD single page</title>
<style>
table, th, td {
border: solid 1px #000;
text-align: left;
}
</style>
</head>
<body>
<!-- Alert jika CRUD data -->
<?php if (isset($_SESSION['alert'])) : ?>
<h2>
<?php
echo $_SESSION['alert'];
unset($_SESSION['alert']);
?>
</h2>
<?php endif ?>
<!-- Form CRUD data -->
<form action="server.php" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="text" name="nama" placeholder="Masukan Nama" value="<?php echo $nama; ?>">
<input type="text" name="kota" placeholder="Masukan Kota" value="<?php echo $kota; ?>">
<?php if ($update == true): ?>
<input type="submit" name="update" value="Update">
<?php else: ?>
<input type="submit" name="save" value="Save">
<?php endif ?>
</form>
<!-- Table data -->
<table>
<thead>
<th>Nama</th>
<th>Kota</th>
<th colspan="2">Setting</th>
</thead>
<?php while ($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['nama']; ?></td>
<td><?php echo $row['kota']; ?></td>
<td><a href="index.php?edit=<?php echo $row['id'] ?>">Edit</a></td>
<td><a href="server.php?del=<?php echo $row['id'] ?>">Delete</a></td>
</tr>
<?php } ?>
</table>
</body>
</html>