-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateDataExtra.php
More file actions
47 lines (37 loc) · 1.27 KB
/
updateDataExtra.php
File metadata and controls
47 lines (37 loc) · 1.27 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
<?php
//連接php與sql
//$conn = mysqli_connect("localhost","administrator","123456","bookcase");
require 'connect.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$書名 = $_POST['bookName'];
$ISBN = $_POST['ISBN'];
$介紹 = $_POST['introduction'];
$類型 = $_POST['inlineRadioOptions']?? null;
$bookId=$_POST['bookId'];
$sql = "UPDATE books SET 書名 = ?, ISBN = ?, 介紹 = ?, 類型 = ? WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssi", $書名, $ISBN, $介紹, $類型,$bookId);
$stmt->execute();
if ($stmt->affected_rows >= 0) {
// 執行語句並檢查是否成功
if ($stmt->execute()) {
// 插入成功後重定向到指定頁面
header("Location: http://localhost/bookcase/bookMainCode.php");
exit(); // 確保重定向後停止腳本執行
} else {
echo "錯誤: " . $stmt->error;
}
/*$row = $stmt->fetch_assoc();
$bookName = $row['書名'];
$isbn = $row['ISBN'];
$introduction = $row['介紹'];
$category = $row['類型']; */
} else {
echo "修改失敗";
exit();
}
//
}
$stmt->close();
$conn->close();
?>