-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookMainCode.php
More file actions
68 lines (56 loc) · 2.04 KB
/
bookMainCode.php
File metadata and controls
68 lines (56 loc) · 2.04 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
<?php
//連接php與sql
//$conn = mysqli_connect("localhost","administrator","123456","bookcase");
//$conn = mysqli_connect("localhost", "root", "", "bookcase");
require 'connect.php';
//檢查連線是否成功
if ($conn->connect_error) {
die( $conn->connect_error."連線失敗。" );
}
// SQL 查詢
$sql = "SELECT id,書名,ISBN, 介紹,類型 FROM books";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>圖書管理系統</title>
</head>
<body>
<center>
<table border="1">
<?php
// 輸出資料到表格
if ($result->num_rows >= 0) {
echo "<tr>";
echo "<td>書名</td> <td> ISBN </td> <td> 介紹 </td> <td> 類型 </td>
<td> <button><a href='http://localhost/bookcase/addData'>新增</a></button> </td>";
echo "</tr>";
while($row = $result->fetch_assoc()) {
echo "</tr>";
echo "<td>" . $row["書名"] . "</td>",
"<td>" . $row["ISBN"] . "</td>",
"<td>" . $row["介紹"] . "</td>",
"<td>" . $row["類型"] . "</td>",
"<td>
<form action='updateData.php' method='post' style='display:inline;'>
<input type='hidden' name='bookId' value='" . $row["id"] . "'>
<button type='submit'>修改</button>
</form>
<form action='deleteData.php' method='post' style='display:inline;'>
<input type='hidden' name='bookId' value='" . $row["id"] . "'>
<button type='submit'>刪除</button>
</form>
</td>";
echo "</tr>";
}
} else {
echo "無資料";
}
$conn->close();
?>
</table>
</center>
</body>
</html>