-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpemilik.php
64 lines (47 loc) · 1.43 KB
/
pemilik.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
<!DOCTYPE html>
<html lang="en">
<!-- HEAD -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CRUD pemilik</title>
</head>
<!-- BODY -->
<body>
<h1>1. koneksi database</h1>
<?php
// INISIALISASI NAMA
$serverName = "localhost";
$user = "root";
$password = "";
$databaseName = "dss_kost_v2";
// KONEKSI DATABASE
$connection = mysqli_connect($serverName, $user, $password, $databaseName);
// ERROR HANDLING
if (mysqli_connect_errno()) {
echo "terjadi error" . mysqli_connect_errno();
} else {
echo "koneksi database berhasil";
}
?>
<h1>2. Membaca Tabel</h1>
<?php
$cekNama = isset($_GET['nama']);
if ($cekNama) {
$dataYangDimasukkan = $_GET['nama'];
$insertPemilik = "INSERT INTO `dss_pemilik`(`nama`) VALUES ('" . $dataYangDimasukkan . "')";
mysqli_query($connection, $insertPemilik);
}
$queryPemilik = "SELECT * FROM `dss_pemilik`";
$hasil = mysqli_query($connection, $queryPemilik);
// READ DATA
while ($arrayOfHasil = mysqli_fetch_assoc($hasil)) {
echo $arrayOfHasil["id"] . ". ";
echo $arrayOfHasil["nama"];
echo "<a href='hapus.php?id=" . $arrayOfHasil['id'] . "'>hapus</a>";
echo "<a href='update_form.php?nama=" . $arrayOfHasil['nama'] . "'>update</a>";
echo "</br>";
}
?>
</body>
</html>