-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_listing.php
More file actions
188 lines (178 loc) · 14.1 KB
/
edit_listing.php
File metadata and controls
188 lines (178 loc) · 14.1 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
<?php
include 'db_connection.php';
session_start();
$productID = 0;
if(isset($_GET['product'])){
$productID = $_GET['product'];
}else{
$productID = $_POST['productID'];
}
$check = 0;
if(isset($_POST['submit'])){
$brandID = 0;
$brand = strtoupper($_POST['brand']);
$sql = "SELECT * FROM brand WHERE UPPER(brand)='$brand'";
$result = $conn->query($sql);
$rest = $result->fetch_assoc();
if(strlen($rest['brand']) == 0){
$sql = "INSERT INTO brand (brand) VALUES ('$_POST[brand]')";
if ($conn->query($sql) === TRUE) {
//echo "Record updated successfully";
} else {
//echo "Error updating record: " . $conn->error . "<br";
}
$sql = "SELECT * FROM brand WHERE brand='$_POST[brand]'";
$result = $conn->query($sql);
$bran = $result->fetch_assoc();
$brandID = $bran['brand_ID'];
} else{
$brandID = $rest['brand_ID'];
}
$price = str_replace('$', ' ', $_POST['price']);
$listPrice = str_replace('$', ' ', $_POST['listPrice']);
$sql = "UPDATE products
SET title='$_POST[title]', brand=$brandID, quantity=$_POST[quantity], price=$price ,list_price=$listPrice, categories=$_POST[categories], description='$_POST[description]'
WHERE product_ID=$_POST[productID]";
if ($conn->query($sql) === TRUE) {
//echo "Record updated successfully";
$check = 1;
} else {
//echo "Error updating record: " . $conn->error;
}
}
//TEMPLATES
include 'templates/head.html';
include 'templates/nav-bar.php';
include 'templates/search-bar.php';
?>
<main class="flex w-full">
<?php
//TEMPLATES
include 'templates/seller-side-bar.php';
?>
<section class="w-full p-4">
<div class="w-full text-md">
<div class="mt-10 sm:mt-0">
<div class="md:grid md:grid-cols-3 md:gap-6">
<div class="mt-5 md:mt-0 md:col-span-2">
<?php
if($check == 1) echo "<div class='text-gray-500 text-center font-bold'>Succesfully updated your product!</div>";
?>
<form action="edit_listing.php" method="POST">
<div class="shadow overflow-hidden sm:rounded-md">
<div class="px-4 py-5 bg-white sm:p-6">
<div class="px-4 py-5 sm:px-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">Edit Product</h3>
</div>
<div class="grid grid-cols-6 gap-6">
<?php
$sql = "SELECT * FROM products INNER JOIN brand ON products.brand=brand.brand_ID WHERE products.product_ID=$productID";
$result = $conn->query($sql);
$res = $result->fetch_assoc();
?>
<!--product Id-->
<input hidden type="text" id="productID" name="productID" value="<?php echo $productID ?>">
<!--Product title-->
<div class="col-span-6 sm:col-span-3">
<label for="title" class="block text-sm font-medium text-gray-700">Product Name</label>
<input required type="text" id="title" name="title" value='<?php echo $res['title'] ?>' class="appearance-none rounded relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product brand-->
<div class="col-span-6 sm:col-span-3">
<label for="brand" class="block text-sm font-medium text-gray-700">Brand</label>
<input required type="text" id="brand" name="brand" value='<?php echo $res['brand'] ?>' class="appearance-none rounded relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product category-->
<div class="col-span-6 sm:col-span-3">
<label for="catagory" class="block text-sm font-medium text-gray-700">Product Category</label>
<select id="categories" name="categories" class="appearance-none rounded relative block w-1/2 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">>
<?php
$sql = "SELECT * FROM categories";
$resu = $conn->query($sql);
while($use = mysqli_fetch_array($resu)) {
if($use['categories_ID'] > 1){
if($res['categories'] == $use['categories_ID']){
echo "<option selected value='" . $use['categories_ID'] . "'>" . $use['categories'] . "</option>";
}else{
echo "<option value='" . $use['categories_ID'] . "'>" . $use['categories'] . "</option>";
}
}
}
?>
</select>
</div>
<!--product condition-->
<div class="col-span-6 sm:col-span-3">
<label for="productCondition" class="block text-sm font-medium text-gray-700">Condition</label>
<select required type="text" id="productCondition" name="productCondition" class="appearance-none rounded relative block w-1/2 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">>
<option value="productCondition">--------------</option>
<option value="New">New</option>
<option value="Used">Used</option>
</select>
</div>
<!--Product price-->
<div class="col-span-6 sm:col-span-3">
<label for="price" class="block text-sm font-medium text-gray-700">Price</label>
<input required type="text" id="price" pattern='[0-9.$]+' name="price" value='$<?php echo $res['price'] ?>' class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product list price-->
<div class="col-span-6 sm:col-span-3">
<label for="listPrice" class="block text-sm font-medium text-gray-700">List Price</label>
<input required type="text" id="listPrice" pattern='[0-9.$]+' name="listPrice" value='$<?php echo $res['list_price'] ?>' class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product discount percent-->
<div class="col-span-6 sm:col-span-3">
<label for="discount_percent" class="block text-sm font-medium text-gray-700">Discount</label>
<input type="number" id="discount_percent" name="discount_percent" placeholder="Discount" class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product quantity-->
<div class="col-span-6 sm:col-span-3">
<label for="quantity" class="block text-sm font-medium text-gray-700">Quantity</label>
<input required type="text" id="quantity" pattern='[0-9]+' name="quantity" value='<?php echo $res['quantity'] ?>' class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product size-->
<div class="col-span-6 sm:col-span-3">
<label for="size" class="block text-sm font-medium text-gray-700">Size</label>
<input type="text" id="size" name="size" placeholder="Size" class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product weight-->
<div class="col-span-6 sm:col-span-3">
<label for="weight" class="block text-sm font-medium text-gray-700">Weight</label>
<input type="text" id="weight" name="weight" placeholder="Weight" class="appearance-none rounded relative block w-1/3 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
<!--Product description-->
<div class="col-span-6">
<label for="description" class="block text-sm font-medium text-gray-700">Product Description</label>
<textarea required id="description" name="description" row="20" cols="40" wrap="soft" class="resize-none h-40 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 mt-1 block w-full sm:text-sm border border-gray-300 rounded-md"><?php echo $res['description'] ?></textarea>
</div>
</div>
</div>
<!-- File Button -->
<div class="col-span-6">
<label class="block text-sm font-medium text-gray-700" for="image">Main Image</label>
<div class="col-md-4">
<input id="image" name="image" type="file" class="appearance-none rounded relative block w-1/2 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
</div>
<!-- File Button
<div class="col-span-6">
<label class="block text-sm font-medium text-gray-700" for="extraImage">Extra Images</label>
<div class="col-md-4">
<input id="extraImage" name="extraImage" type="file" class="appearance-none rounded relative block w-1/2 px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm">
</div>
</div>
-->
<div class="px-4 py-3 bg-gray-50 text-right sm:px-6">
<button id="submit" name="submit" type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-gray-900 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</main>
<?php // TEMPLATES
include 'templates/footer.html';
?>