-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
322 lines (288 loc) · 10.7 KB
/
update.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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php include 'dbconnect.php' ?>
<!DOCTYPE html>
<html>
<head>
<title>Update Records</title>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Source+Code+Pro'>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="project-team19.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style> body {font-family: 'Source Code Pro', sans-serif; color: black;} </style>
</head>
<div style="text-align:center;">
<body>
<div class="menu-bar">
<div>
<a href="index.php"><img id="logo" src="logo.png"></a>
</div>
<div>
<a href="index.php">Home</a>
</div>
<div>
<a href="types_of_services.php">Types Of Services</a>
</div>
<div>
<a href="reviews.php">Reviews</a>
</div>
<div>
<a href="shopping_cart.php">Shopping Cart</a>
</div>
<div>
<a href="about_us.php">About Us</a>
</div>
<div>
<a href="contact_us.php">Contact Us</a>
</div>
<div class="dropdown">
<button class="dropbtn">DB Maintain</button>
<div class="dropdown-content">
<a href="insert.php">Insert</a>
<a href="delete.php">Delete</a>
<a href="select.php">Select</a>
<a href="update.php">Update</a>
</div>
</div>
<div>
<a href="logout.php">Log Out</a>
</div>
</div>
<h1 style="text-align:center;">Update Records</h1>
<form class="update" action="update.php" method="post">
<div class="form-group">
<label for="seeAnotherField">Which table would you like to Update?</label><br>
<select class="form-control" name="table" id="seeAnotherField">
<option value="orders">orders</option>
<option value="items">items</option>
<option value="users">users</option>
<option value="trip">trip</option>
<option value="truck">truck</option>
<option value="stock">stock</option>
<option value="payment">payment</option>
</select>
</div>
<div class="form-group" id="orderDiv">
<label for="orderField">Choose type:</label>
<select class="form-control" name="orderVari" id="orderVari">
<option value="date_issued">Date Issued</option>
<option value="date_recieved">Date Recieved</option>
<option value="total_price">Total Price</option>
<option value="branch">Branch</option>
</select>
<p>Enter Order ID: <p>
<input type="text" id="orderOldItem" name="orderOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="orderNewItem" name="orderNewItem"><br>
</div>
<div class="form-group" id="itemDiv">
<label for="itemField">Choose type:</label>
<select class="form-control" name="itemVari" id="itemVari">
<option value="name">Name</option>
<option value="price">Price</option>
<option value="quantity">Quantity</option>
</select>
<p>Enter Item ID: <p>
<input type="text" id="itemOldItem" name="itemOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="itemNewItem" name="itemNewItem"><br>
</div>
<div class="form-group" id="userDiv">
<label for="userField">Choose type:</label>
<select class="form-control" name="userVari" id="userVari">
<option value="name">Name</option>
<option value="balance">Balance</option>
<option value="tel_no">Phone Number</option>
<option value="home_address">Home Address</option>
<option value="email">Email</option>
<option value="login_id">Login ID</option>
<option value="password">Password</option>
</select>
<p>Enter User ID: <p>
<input type="text" id="userOldItem" name="userOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="userNewItem" name="userNewItem"><br>
</div>
<div class="form-group" id="tripDiv">
<label for="tripField">Choose type:</label>
<select class="form-control" name="tripVari" id="tripVari">
<option value="branch">Branch</option>
<option value="destination">Destination</option>
<option value="distance">Distance</option>
</select>
<p>Enter Trip ID: <p>
<input type="text" id="tripOldItem" name="tripOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="tripNewItem" name="tripNewItem"><br>
</div>
<div class="form-group" id="truckDiv">
<label for="truckField">Choose type:</label>
<select class="form-control" name="truckVari" id="truckVari">
<option value="truck_code">Truck code</option>
<option value="available">Availability</option>
</select>
<p>Enter Truck ID: <p>
<input type="text" id="truckOldItem" name="truckOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="truckNewItem" name="truckNewItem"><br>
</div>
<div class="form-group" id="stockDiv">
<label for="stockField">Choose type:</label>
<select class="form-control" name="stockVari" id="stockVari">
<option value="name">Name</option>
<option value="price">Price</option>
<option value="quantity">Quantity</option>
</select>
<p>Enter Shopping ID: <p>
<input type="text" id="stockOldItem" name="stockOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="stockNewItem" name="stockNewItem"><br>
</div>
<div class="form-group" id="paymentDiv">
<label for="paymentField">Choose type:</label>
<select class="form-control" name="paymentVari" id="paymentVari">
<option value="cc_num">CC Number</option>
<option value="ccv">CCV</option>
</select>
<p>Enter User ID: <p>
<input type="text" id="paymentOldItem" name="paymentOldItem"><br>
<p>Enter replacement:<p>
<input type="text" id="paymentNewItem" name="paymentNewItem"><br>
</div>
<input type="submit" name="submit" value="Submit">
</form>
<script>
$("#seeAnotherField").change(function() {
if ($(this).val() == "items") {
$('#itemDiv').show();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#tripDiv').hide();
$('#truckDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "users") {
$('#userDiv').show();
$('#itemDiv').hide();
$('#orderDiv').hide();
$('#tripDiv').hide();
$('#truckDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "orders") {
$('#orderDiv').show();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#tripDiv').hide();
$('#truckDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "trip") {
$('#tripDiv').show();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#truckDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "truck") {
$('#truckDiv').show();
$('#tripDiv').hide();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "shopping") {
$('#truckDiv').hide();
$('#tripDiv').hide();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "stock") {
$('#stockDiv').show();
$('#truckDiv').hide();
$('#tripDiv').hide();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#paymentDiv').hide();
} else if ($(this).val() == "payment") {
$('#paymentDiv').show();
$('#truckDiv').hide();
$('#tripDiv').hide();
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#stockDiv').hide();
} else {
$('#itemDiv').hide();
$('#userDiv').hide();
$('#orderDiv').hide();
$('#tripDiv').hide();
$('#truckDiv').hide();
$('#stockDiv').hide();
$('#paymentDiv').hide();
}
});
$("#seeAnotherField").trigger("change");
</script>
</body>
</div>
</html>
<?php
require __DIR__ . './functions.php';
if (isset($_POST['submit'])) {
$table = $_POST['table'];
if ($_POST['table'] === 'orders') {
$orderOldItem = $_POST['orderOldItem'];
echo $orderOldItem;
$orderNewItem = $_POST['orderNewItem'];
$vari = $_POST['orderVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$orderNewItem' WHERE order_id=$orderOldItem;");
echo "Updated Order Table";
}
if ($_POST['table'] === 'items') {
$itemOldItem = $_POST['itemOldItem'];
$itemNewItem = $_POST['itemNewItem'];
$vari = $_POST['itemVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$itemNewItem' WHERE item_id=$itemOldItem;");
echo "Updated Item Table";
}
if ($_POST['table'] === 'users') {
$userOldItem = $_POST['userOldItem'];
$userNewItem = $_POST['userNewItem'];
$vari = $_POST['userVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$userNewItem' WHERE user_id=$userOldItem;");
echo "Updated User Table";
}
if ($_POST['table'] === 'trip') {
$OldItem = $_POST['tripOldItem'];
$NewItem = $_POST['tripNewItem'];
$vari = $_POST['tripVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$NewItem' WHERE trip_id=$OldItem;");
echo "Updated Trip Table";
}
if ($_POST['table'] === 'truck') {
$OldItem = $_POST['truckOldItem'];
$NewItem = $_POST['truckNewItem'];
$vari = $_POST['truckVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$NewItem' WHERE truck_id=$OldItem;");
echo "Updated Truck Table";
}
if ($_POST['table'] === 'stock') {
$OldItem = $_POST['stockOldItem'];
$NewItem = $_POST['stockNewItem'];
$vari = $_POST['stockVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$NewItem' WHERE stock_id=$OldItem;");
echo "Updated Stock Table";
}
if ($_POST['table'] === 'payment') {
$OldItem = $_POST['paymentOldItem'];
$NewItem = $_POST['paymentNewItem'];
$vari = $_POST['paymentVari'];
$result = $connect -> query("UPDATE $table SET $vari = '$NewItem' WHERE user_id=$OldItem;");
echo "Updated Payment Table";
}
}
?>