-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropMenu.php
More file actions
86 lines (73 loc) · 2.38 KB
/
dropMenu.php
File metadata and controls
86 lines (73 loc) · 2.38 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Basic CRUD</title>
</head>
<body>
<?php
require 'config.php'; // include file connect to db
include 'menu.php'; //include menu list from menu.php, you may edit accordingly
// Retrieve pelanggan names from database
$sql = "SELECT idPelanggan, namaSendiri FROM pelanggan";
$result = $conn->query($sql);
// Form submission handling
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$idPelanggan = $_POST['namaSendiri'];
$kereta = $_POST['kereta'];
$plat = $_POST['noPlat'];
// Insert into kereta table
$insertSql = "INSERT INTO kereta (idPelanggan, kereta, plat) VALUES ('$idPelanggan', '$kereta', '$plat')";
if ($conn->query($insertSql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $insertSql . "<br>" . $conn->error;
}
}
?>
<form action="" method="post">
<label for="namaSendiri">Nama Sendiri:</label>
<select name="namaSendiri" id="namaSendiri">
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row['idPelanggan'] . "'>" . $row['namaSendiri'] . "</option>";
}
}
?>
</select><br>
<label for="kereta">Kereta:</label>
<input type="text" name="kereta" id="kereta" required><br>
<label for="noPlat">No Plat:</label>
<input type="text" name="noPlat" id="noPlat" required><br>
<input type="submit" value="Submit">
</form>
<br>
<?php
// Display table of data
$sql = "SELECT pelanggan.idPelanggan, pelanggan.namaSendiri, kereta.kereta, kereta.plat FROM pelanggan JOIN kereta ON pelanggan.idPelanggan = kereta.idPelanggan";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Kereta</th>
<th>Plat</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["idPelanggan"] . "</td>
<td>" . $row["namaSendiri"] . "</td>
<td>" . $row["kereta"] . "</td>
<td>" . $row["plat"] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
include 'footer.php';
?>
</body>
</html>