-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsach.php
More file actions
109 lines (101 loc) · 3.73 KB
/
Copy pathsach.php
File metadata and controls
109 lines (101 loc) · 3.73 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
// Kết nối cơ sở dữ liệu
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$action = $_POST['action'];
$conn = mysqli_connect('localhost', 'root', '', 'sqlquanlythuvien');
if ($conn->connect_error) {
die("Kết nối thất bại: " . $conn->connect_error);
}
switch ($action) {
case 'add':
$mas = $_POST['mas'];
$mals = $_POST['mals'];
$tens = $_POST['tens'];
$matg = $_POST['matg'];
$soluong = $_POST['soluong'];
$hinhs = $_POST['hinhs'];
$manxb = $_POST['manxb'];
$namxb = $_POST['namxb'];
$trangthai = $_POST['trangthai'];
$sql = "INSERT INTO `sach`(`MaS`, `MaLS`, `TenS`, `MaTG`, `SoLuong`,`HinhAnh`, `MaNXB`, `NamXB`, `TrangThai`) VALUES ('$mas','$mals','$tens','$matg','$soluong','$hinhs','$manxb','$namxb','$trangthai')";
$result = $conn->query($sql);
if (!$result) {
echo "Thêm thất bại .";
} else {
echo "Thêm thành công ";
}
break;
case 'update':
$mas = $_POST['mas'];
$mals = $_POST['mals'];
$tens = $_POST['tens'];
$matg = $_POST['matg'];
$soluong = $_POST['soluong'];
$hinhs = $_POST['hinhs'];
$manxb = $_POST['manxb'];
$namxb = $_POST['namxb'];
$trangthai = $_POST['trangthai'];
$sql = "UPDATE `sach` SET `MaLS`='$mals',`TenS`='$tens',`MaTG`='$matg',`SoLuong`='$soluong',`HinhAnh`='$hinhs',`MaNXB`='$manxb',`NamXB`='$namxb',`TrangThai`='$trangthai' WHERE `MaS`='$mas'";
$result = $conn->query($sql);
if (!$result) {
echo "Sửa dữ liệu thất bại.";
} else {
echo "sửa dữ liệu thành công";
}
break;
case 'delete':
$mas= $_POST['mas'];
$sql = "DELETE FROM `sach` WHERE `MaS`=$mas";
$result = $conn->query($sql);
if (!$result) {
echo "xóa thất bại .";
} else {
// echo "xóa thành công ";
}
break;
case 'getmals':
$tam="";
$sql = "SELECT `MaLS` FROM `theloai` WHERE 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$tam=$tam."<option value=".$row['MaLS'].">".$row['MaLS']."</option>";
}
echo ($tam);
} else {
echo "khong co du lieu .";
}
break;
case 'getmatg':
$tam="";
$sql = "SELECT `MaTG` FROM `tacgia` WHERE 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$tam=$tam."<option value=".$row['MaTG'].">".$row['MaTG']."</option>";
}
echo ($tam);
} else {
echo "khong co du lieu .";
}
break;
case 'getmanxb':
$tam="";
$sql = "SELECT `MaNXB` FROM `nhaxuatban` WHERE 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$tam=$tam."<option value=".$row['MaNXB'].">".$row['MaNXB']."</option>";
}
echo ($tam);
} else {
echo "khong co du lieu .";
}
break;
}
mysqli_close($conn);
}
?>