-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct.php
188 lines (143 loc) · 5.51 KB
/
product.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
// 数据库连接信息
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bowwow";
// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("Failed " . $conn->connect_error);
}
// 查询所有商品
$sql = "SELECT * FROM product";"SELECT product.*, category.name AS category_name FROM product JOIN category ON product.cate_id = category.id";
$result = $conn->query($sql);
// 处理表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 处理添加商品请求
if (isset($_POST["add_product"])) {
$name = $_POST["name"];
$price = $_POST["price"];
$description = $_POST["description"];
$sql = "INSERT INTO product (name, price, description) VALUES ('$name', '$price', '$description')";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
// 处理编辑商品请求
if (isset($_POST["edit_product"])) {
$id = $_POST["id"];
$name = $_POST["name"];
$price = $_POST["price"];
$description = $_POST["description"];
$sql = "UPDATE products SET name='$name', price='$price', description='$description' WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
// 处理删除商品请求
if (isset($_POST["delete_category"])) {
$id = $_POST["id"];
$sql = "DELETE FROM products WHERE id=$id";
if ($conn->query($sql) === TRUE) {
echo "scuessful";
} else {
echo "Failed: " . $conn->error;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Product Management</title>
<!-- Remote style sheet -->
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css"/>
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
<!-- Local style sheet relative to workspace folder -->
<link rel="stylesheet" href="/style.css">
<script src="css/theme.css"></script>
<!-- Local style sheet relative to this file -->
<link rel="stylesheet" href="theme.css">
<!-- Embedded style sheet -->
<style>
table.center{
margin:auto auto auto -20%;
width:115%;
border-collapse:collapse;
text-align: center;
}
table.center th, table.center td {
padding: 8px;
border-bottom: 1px solid #ddd;
}
table.center th{
background-color: #D8CCC4;
}
h2{
margin-left: -20%;
}
div.search_clearfix{
float:right;
margin-right:calc(5%);
}
</style>
</head>
<body>
<?php include 'include/sidebar.php'; ?>
<div class="mdui-drawer-body-left" id="body" >
<!--主题-->
<h2>Product List</h2>
<!-- SEARCHING -->
<div class="margin" id="page_style">
<div class="operation clearfix">
<span class="submenu"><a href="proadd.php" style ="margin-left:-20%;"class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-amber-100" title="Add Product"><i class="fa fa-edit"></i> Add Product</a></span>
<div class="search_clearfix">
<label class="label_name">Product Searching:</label><input name="" type="text" class="form-control col-xs-6"/><button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-amber-100" onclick="" type="button" ><i class="fa fa-search"></i> Search</button>
</div>
</div>
<!--列表展示-->
<h3>
<div class="list_Exhibition margin-sx">
<table class="table table_list table_striped table-bordered center" id="sample-table">
<tr>
<th width="5%"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
<th width="10%">ID</th>
<th width="10%">Icon</th>
<th width="15%">Product Name</th>
<th width="10%">Category</th>
<th width="5%">Hot</th>
<th width="15%">Price</th>
<th width="10%">StockQty</th>
<th width="30%">Operation</th>
</tr>
<?php
// 在这里添加您的PHP代码
while($product=$result->fetch_assoc()){
echo "<table class='table table_list table_striped table-bordered center'>";
echo "<tr>";
echo '<td width="5%">'.'<label>'.'<input type="checkbox" class="ace"><span class="lbl">'.'</span>'.'</label>'.'</td>';
echo '<td width="10%">'.$product['id'].'</td>';
echo '<td width="10%"><img src="./images/product_img/'.$product['id'].'.jpg"alt="'.$product['image_path'].'"width="100px"height="100px"></td>';
echo '<td width="15%">'.$product['name'].'</td>';
echo '<td width="10%">'.$product['cate_id'].'</td>';
echo '<td width="5%">' . ($product['is_hot'] == 0 ? 'No' : ($product['is_hot'] == 1 ? 'Yes' : '')) . '</td>';
echo '<td width="15%">'."$".$product['price'].'</td>';
echo '<td width="10%">'.$product['stock_qty'].'</td>';
echo '<td width="30%"><a href="proedit.php?id='.$product['id'].'">Edit</a> ';
echo '<a href="Delete.php?cate=product&id='.$product['id'].'">Delete</a></td>';
echo "</tr>";
echo "</table>";
}
?>
</table>
</div>
</h3>
</div>
</body>
</html>