-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
231 lines (160 loc) · 8.05 KB
/
insert.php
File metadata and controls
231 lines (160 loc) · 8.05 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
include('db.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.top {
font-size: 28px;
background-color: #e6e6e6;
text-align: center;
padding: 8px 0;
margin-bottom: 20px;
box-shadow: 0 -20px 15px -10px rgba(155, 155, 155, 0.3) inset,
0 20px 15px -10px rgba(155, 155, 155, 0.3) inset,
0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="top">
<i class="fa fa-dashboard fa-fw">
</i> Dashboard
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-money fa-fw"></i> Insert Products
</h3>
</div>
<div class="panel-body">
<form method="post" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group">
<label class="col-md-3 control-label">Product Title/Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="product_title" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Category</label>
<div class="col-md-6">
<select class="form-control" name="p_cat_id">
<option>Select a Product Category</option>
<?php
$get_p_category = "select * from product_categories";
$run_p_category = mysqli_query($con, $get_p_category);
while ($p_cat_row = mysqli_fetch_array($run_p_category)) {
$p_cat_id = $p_cat_row['p_cat_id'];
$p_cat_title = $p_cat_row['p_cat_title'];
echo "
<option value='$p_cat_id'>$p_cat_title</option>
";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Category</label>
<div class="col-md-6">
<select class="form-control" name="cat_id">
<option>Select a Category</option>
<?php
$get_category = "select * from category";
$run_category = mysqli_query($con, $get_category);
while ($cat_row = mysqli_fetch_array($run_category)) {
$cat_id = $cat_row['cat_id'];
$cat_title = $cat_row['cat_title'];
echo "
<option value='$cat_id'>$cat_title</option>
";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Image # 1</label>
<div class="col-md-6">
<input type="file" class="form-control" name="product_img1" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Image # 2</label>
<div class="col-md-6">
<input type="file" class="form-control" name="product_img2" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Price</label>
<div class="col-md-6">
<input type="text" class="form-control" name="product_price" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Keywords</label>
<div class="col-md-6">
<input type="text" class="form-control" name="product_keywords" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Description</label>
<div class="col-md-6">
<textarea class="form-control" name="product_desc" cols="19" rows="6"></textarea>
</div>
</div>
<div class="form-group" style="display: flex;justify-content:center">
<div class="col-md-3">
<input name="submit" type="submit" class="btn btn-primary form-control" value="Insert Product">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea'
});
</script>
</body>
</html>
<?php
if (isset($_POST['submit'])) {
$p_cat_id = $_POST['p_cat_id'];
$cat_id = $_POST['cat_id'];
$product_title = $_POST['product_title'];
$product_img1 = $_FILES['product_img1']['name'];
$product_img2 = $_FILES['product_img2']['name'];
$product_price = $_POST['product_price'];
$product_keywords = $_POST['product_keywords'];
$product_desc = $_POST['product_desc'];
$temp_name1 = $_FILES['product_img1']['tmp_name'];
$temp_name2 = $_FILES['product_img2']['tmp_name'];
move_uploaded_file($temp_name1, "img/products/$product_img1");
move_uploaded_file($temp_name2, "img/products/$product_img2");
$insert_product = "Insert into products (p_cat_id,cat_id,date,product_title,product_img1,product_img2,product_price,product_keywords,product_desc)
values ('$p_cat_id','$cat_id',NOW(),'$product_title','$product_img1','$product_img2','$product_price','$product_keywords','$product_desc')";
$run_insert_product = mysqli_query($con, $insert_product);
if ($run_insert_product) {
echo "<script>alert('Product Inserted')</script>";
echo "<script>window.open('index.php','_self')</script>";
}
}
?>