-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_product.php
690 lines (641 loc) · 33.8 KB
/
order_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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
<?php
if (!isset($_SESSION))
{
session_start();
}
if(isset($_SESSION["login_usertype"]))
{//some one is logon
$system_usertype=$_SESSION["login_usertype"];
$system_username=$_SESSION["login_username"];
$system_userid=$_SESSION["login_userid"];
}
else
{//guest
$system_usertype="Guest";
}
include "config.php";
//insert sql start
if(isset($_POST["btnsave"]))
{
$sqlinsert="INSERT INTO order_product(order_id,product_id,quantity)
VALUES('".mysqli_real_escape_string($con,$_POST["txtorderid"])."',
'".mysqli_real_escape_string($con,$_POST["txtproductid"])."',
'".mysqli_real_escape_string($con,$_POST["txtquantity"])."')";
$resultinsert=mysqli_query($con,$sqlinsert) or die ("sql error in sqlinsert" . mysqli_error($con));
if($resultinsert)
{
if (isset($_GET["edit_pk1"]))
{
$address="index.php?pg=order_detail.php&option=fullview&pk=".$_GET["edit_pk1"];
echo '<script> alert("Data insert Sucessfully");
window.location.href="'.$address.'";</script>';
}
else
{
if(isset($_SESSION["session_addtocart"]))
{
unset($_SESSION["session_addtocart"]);
}
if (!isset($_SESSION["session_orderid"]))
{
$_SESSION["session_orderid"]=$_POST["txtorderid"];
}
echo '<script> alert("Data stored successfully"); </script>';
}
}
}
//insert sql end
//update code start
if(isset($_POST["btnsavechanges"]))
{
$sqlupdate="UPDATE order_product SET
quantity='".mysqli_real_escape_string($con,$_POST["txtquantity"])."'
WHERE order_id='".mysqli_real_escape_string($con,$_POST["txtorderid"])."' AND product_id='".mysqli_real_escape_string($con,$_POST["txtproductid"])."'";
$resultupdate=mysqli_query ($con,$sqlupdate) or die("Error in sqlupdate" . mysqli_error($con));
if ($resultupdate)
{
if (isset($_GET["edit_pk1"]))
{
$address="index.php?pg=order_detail.php&option=fullview&pk=".$_POST["txtorderid"];
}
else
{
$address="index.php?pg=order_product.php&option=add";
}
echo '<script> alert("Data updated Sucessfully");
window.location.href="'.$address.'";</script>';
}
}
//update code End
?>
<script>
function load_subcategory()
{
var category_id=document.getElementById("txtcategoryid").value;
if (category_id!="select_option")
{//if select any category
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var get_response = xmlhttp.responseText.trim();
document.getElementById("txtsubcategoryid").innerHTML=get_response;
document.getElementById("txtproductid").innerHTML='<option value="select_option">Select product ID</option>';
document.getElementById("txtunitprice").value="";
}
};
xmlhttp.open("GET", "ajaxpage.php?frompage=product_category&ajaxcategoryid=" + category_id, true);
xmlhttp.send();
}
else
{//if not select any category
document.getElementById("txtsubcategoryid").innerHTML='<option value="select_option">Select The Sub Category ID</option>';
document.getElementById("txtproductid").innerHTML='<option value="select_option">Select product ID</option>';
document.getElementById("txtunitprice").value="";
}
}
</script>
<script>
function load_product()
{
var subcategory_id=document.getElementById("txtsubcategoryid").value;
var order_id=document.getElementById("txtorderid").value;
if (subcategory_id!="select_option")
{//if select any subcategory
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var get_response = xmlhttp.responseText.trim();
document.getElementById("txtproductid").innerHTML=get_response;
document.getElementById("txtunitprice").value="";
}
};
xmlhttp.open("GET", "ajaxpage.php?frompage=order_product_subcategory&ajaxsubcategoryid=" + subcategory_id+"&ajaxorderid=" + order_id, true);
xmlhttp.send();
}
else
{//if not select any subcategory
document.getElementById("txtproductid").innerHTML='<option value="select_option">Select product ID</option>';
document.getElementById("txtunitprice").value="";
}
}
</script>
<script>
function load_unitprice()
{
var product_id=document.getElementById("txtproductid").value;
if (product_id!="select_option")
{//if select any product
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var get_response = xmlhttp.responseText.trim();
document.getElementById("txtunitprice").value=get_response;
}
};
xmlhttp.open("GET", "ajaxpage.php?frompage=order_product_product&ajaxproductid=" + product_id, true);
xmlhttp.send();
}
else
{//if not select any product
document.getElementById("txtunitprice").value="";
}
}
</script>
<script>
function subtotal()
{
var unitprice=document.getElementById("txtunitprice").value;
var quantity=document.getElementById("txtquantity").value;
var subtotal=+quantity * +unitprice;
subtotal=subtotal.toFixed(2);
document.getElementById("txtsubtotal").value=subtotal;
}
</script>
<script>
function reduce()
{
var discount=document.getElementById("txtdiscountprice").value;
var subtotal=document.getElementById("txtsubtotal").value;
var final=+subtotal - +discount;
document.getElementById("txtfinalprice").value=final;
}
</script>
<body>
<?php
if (isset($_GET["option"]))
{
if ($_GET["option"] == "add")
{
?>
<!-- form section start -->
<section class="feature_part padding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<form class="form-horizontal" method="POST" action="">
<div class="card-body">
<center><h4 class="card-title">Add Order Product</h4></center>
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Order ID</label>
<div class="col-sm-3">
<?php
if (isset($_SESSION["session_orderid"]))
{
$generateid=$_SESSION["session_orderid"];
}
else if (isset($_GET["edit_pk1"]))
{
$generateid=$_GET["edit_pk1"];
}
else
{
$sqlgenerateid="SELECT order_id FROM order_product ORDER BY order_id DESC LIMIT 1";
$resultgenerateid=mysqli_query($con,$sqlgenerateid) or die ("Error in sqlgenerateid". mysqli_error($con));
$n=mysqli_num_rows($resultgenerateid);//count the number of records
if($n==1)
{//for other than 1st time
$rowgenerateid=mysqli_fetch_assoc($resultgenerateid);
$generateid=++$rowgenerateid["order_id"];
}
else
{//For 1st time
$generateid="OR00001";
}
}
?>
<input type="text" class="form-control" id="txtorderid" name="txtorderid" placeholder="Order id Here" readonly value="<?php echo $generateid; ?>" required>
</div>
<?php
if(isset($_SESSION["session_addtocart"]))
{
$sqlsessionsubcategory="SELECT subcategory_id FROM product WHERE product_id ='$_SESSION[session_addtocart]'";
$resultsessionsubcategory=mysqli_query($con,$sqlsessionsubcategory) or die ("Error in sqlsessionsubcategory" . mysqli_error($con));
$rowsessionsubcategory=mysqli_fetch_assoc($resultsessionsubcategory);
$sqlsessioncategory="SELECT category_id FROM subcategory WHERE subcategory_id ='$rowsessionsubcategory[subcategory_id]'";
$resultsessioncategory=mysqli_query($con,$sqlsessioncategory) or die ("Error in sqlsessioncategory" . mysqli_error($con));
$rowsessioncategory=mysqli_fetch_assoc($resultsessioncategory);
$sqlproductprice="SELECT price,offer FROM product_price WHERE product_id='$_SESSION[session_addtocart]' AND end_date IS NULL";//produts which are still available
$resultproductprice=mysqli_query($con,$sqlproductprice) or die ("Error in sqlproductprice" . mysqli_error($con));
$rowproductprice=mysqli_fetch_assoc($resultproductprice);
$price=$rowproductprice["price"];
$offer=$rowproductprice["offer"];
if($offer>0)//if offer is applicable
{
$unitprice=$price-(($price*$offer)/100);//price which is after applied offer
}
else //if offer is not applicable
{
$unitprice=$price;//offer is not applicable
}
}
else
{
$unitprice="";//when session is not set
}
?>
<label for="fname" class="col-sm-3 text-right control-label col-form-label"> Category id</label>
<div class="col-sm-3">
<select class="form-control" id="txtcategoryid" name="txtcategoryid" placeholder="category ID Here" onchange="load_subcategory()" required>
<?php
if(isset($_SESSION["session_addtocart"]))
{
$sqlload="SELECT category_id,category_name FROM category WHERE category_id='$rowsessioncategory[category_id]'";
}
else
{
echo ' <option value="select_option">Select The Category ID</option>';//if ot session set
$sqlload="SELECT category_id,category_name FROM category";
}
$resultload=mysqli_query($con,$sqlload) or die ("Error in sqlload" . mysqli_error($con));
while( $rowload=mysqli_fetch_assoc($resultload))
{
echo '<option value="'.$rowload["category_id"].'">'.$rowload["category_name"].'</option>';
}
?>
</select>
</div>
</div>
<!-- field end -->
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label"> Sub Category id</label>
<div class="col-sm-3">
<select class="form-control" id="txtsubcategoryid" name="txtsubcategoryid" onchange="load_product()" placeholder="Subcategory ID Here" required>
<?php
if(isset($_SESSION["session_addtocart"]))
{
$sqlload="SELECT subcategory_id,subcategory_name FROM subcategory WHERE subcategory_id='$rowsessionsubcategory[subcategory_id]'";
$resultload=mysqli_query($con,$sqlload) or die ("Error in sqlload" . mysqli_error($con));
while( $rowload=mysqli_fetch_assoc($resultload))
{
echo '<option value="'.$rowload["subcategory_id"].'">'.$rowload["subcategory_name"].'</option>';
}
}
else
{
echo '<option value="select_option">Select The Sub Category ID</option>';
}
?>
</select>
</div>
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Product ID</label>
<div class="col-sm-3">
<select class="form-control" id="txtproductid" name="txtproductid" onchange="load_unitprice()" placeholder="Actual Product ID Here" required>
<?php
if(isset($_SESSION["session_addtocart"]))
{
$sqlload="SELECT product_id,name FROM product WHERE product_id='$_SESSION[session_addtocart]'";
$resultload=mysqli_query($con,$sqlload) or die ("Error in sqlload" . mysqli_error($con));
while( $rowload=mysqli_fetch_assoc($resultload))
{
echo '<option value="'.$rowload["product_id"].'">'.$rowload["name"].'</option>';
}
}
else
{
echo '<option value="select_option">Select product ID</option>';
}
?>
</select>
</div>
</div>
<!-- field end -->
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Unit Price</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="txtunitprice" name="txtunitprice" value="<?php echo $unitprice; ?>" placeholder="Unit Price Here" required readonly>
</div>
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Quantity</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="txtquantity" name="txtquantity" placeholder="Quantity Here" required onkeypress="return NumberValidation(event)" oninput="subtotal()">
</div>
</div>
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Sub Total</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="txtsubtotal" name="txtsubtotal" placeholder="Sub Total Here" required readonly>
</div>
<!-- field end -->
<!-- button start -->
<div class="form-group row">
<div class="col-sm-12">
<center>
<?php
if (isset($_GET["edit_pk1"]))
{
$address="index.php?pg=order_detail.php&option=fullview&pk=".$_GET["edit_pk1"];
}
else
{
$address="index.php?pg=order_detail.php&option=view";
}
?>
<a href ="<?php echo $address; ?>"><input type="button" class="btn btn-primary" id="btngoback" name="btngoback" value="Go back"></a>
<input type="reset" class="btn btn-danger" id="btnclear" name="btnclear" value="Clear">
<input type="submit" class="btn btn-success" id="btnsave" name="btnsave" value="Save">
</center>
</div>
</div>
<!-- button end -->
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if (isset($_SESSION["session_orderid"]))
{
//list all the order product
?>
<div class="card">
<div class="card-body">
<center> <h5 class="card-title">Order Product Details</h5></center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<thead>
<tr>
<th>Order id</th>
<th>Product ID</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Sub Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$totalprice=0;
$sqlview="SELECT order_id,product_id,quantity FROM order_product WHERE order_id='$_SESSION[session_orderid]'";
$resultview = mysqli_query($con,$sqlview) or die ("Error in sqlview ".mysqli_error($con));
while($rowview=mysqli_fetch_assoc($resultview))
{
$sqlproductname="SELECT name FROM product WHERE product_id='$rowview[product_id]'";
$resultproductname=mysqli_query($con,$sqlproductname) or die ("Error in sqlproductname" . mysqli_error($con));
$rowproductname=mysqli_fetch_assoc($resultproductname);
$sqlcheckprice="SELECT price,offer FROM product_price WHERE product_id='$rowview[product_id]' AND end_date IS NULL";
$resultcheckprice=mysqli_query($con,$sqlcheckprice) or die ("Error in sqlcheckprice" . mysqli_error($con));
$rowcheckprice=mysqli_fetch_assoc($resultcheckprice);
if($rowcheckprice["offer"]>0)
{
$unitprice=$rowcheckprice["price"]-(($rowcheckprice["price"]*$rowcheckprice["offer"])/100);
}
else
{
$unitprice=$rowcheckprice["price"];
}
$unitprice=number_format((float)$unitprice, 2, '.', '');
$subtotal=$rowview["quantity"]*$unitprice;
$totalprice=$totalprice+$subtotal;
echo'<tr>';
echo '<td>'.$rowview["order_id"].'</td>';
echo '<td>'.$rowproductname["name"].'</td>';
echo '<td>'.$rowview["quantity"].'</td>';
echo '<td>'.$unitprice.'</td>';
echo '<td>'.$subtotal.'</td>';
echo '<td>';
echo '<a href="index.php?pg=order_product.php&option=edit&pk1='.$rowview["order_id"].'&pk2='.$rowview["product_id"].'"><button class="btn btn-info">Edit</button></a> ';
echo '<a onclick="return confirmdelete()" href="index.php?pg=order_product.php&option=delete&pk1='.$rowview["order_id"].'&pk2='.$rowview["product_id"].'"><button class="btn btn-danger">Delete</button></a> ';
echo '</td>';
echo'</tr>';
}
echo'<tr>';
echo '<td>Total Price</td>';
echo '<td></td>';
echo '<td></td>';
echo '<td></td>';
echo '<td>'.$totalprice.'</td>';
echo '<td>';
if($totalprice>0)
{
?>
<a href="index.php?pg=order_detail.php&option=add"><button class="btn btn-primary">Finish</button></a>
<?php
}
echo '</td>';
echo'</tr>';
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
?>
</section>
<!-- form section end -->
<?php
}
else if ($_GET["option"] == "view")
{
?>
<div class="card">
<div class="card-body">
<center> <h5 class="card-title">Order Product View</h5></center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<a href="index.php?pg=order_product.php&option=add"><button class="btn btn-primary">Add Record</button></a>
<br><br>
<thead>
<tr>
<th>Order id</th>
<th>Product ID</th>
<th>Quantity</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sqlview="SELECT order_id,product_id,quantity FROM order_product";
$resultview = mysqli_query($con,$sqlview) or die ("Error in sqlview ".mysqli_error($con));
while($rowview=mysqli_fetch_assoc($resultview))
{
$sqlproductname="SELECT name FROM product WHERE product_id='$rowview[product_id]'";
$resultproductname=mysqli_query($con,$sqlproductname) or die ("Error in sqlproductname" . mysqli_error($con));
$rowproductname=mysqli_fetch_assoc($resultproductname);
echo'<tr>';
echo '<td>'.$rowview["order_id"].'</td>';
echo '<td>'.$rowproductname["name"].'</td>';
echo '<td>'.$rowview["quantity"].'</td>';
echo '<td>';
echo '<a href="index.php?pg=order_product.php&option=fullview&pk1='.$rowview["order_id"].'&pk2='.$rowview["product_id"].'"><button class="btn btn-success">View</button></a> ';
echo '<a href="index.php?pg=order_product.php&option=edit&pk1='.$rowview["order_id"].'&pk2='.$rowview["product_id"].'"><button class="btn btn-info">Edit</button></a> ';
echo '<a onclick="return confirmdelete()" href="index.php?pg=order_product.php&option=delete&pk1='.$rowview["order_id"].'&pk2='.$rowview["product_id"].'"><button class="btn btn-danger">Delete</button></a> ';
echo '</td>';
echo'</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
else if ($_GET["option"] == "fullview")
{
$get_orderid =$_GET["pk1"];
$get_productid =$_GET["pk2"];
$sqlfullview = "SELECT * FROM order_product WHERE order_id ='$get_orderid' AND product_id ='$get_productid'";
$resultfullview = mysqli_query($con,$sqlfullview) or die("Sqlfullview error ".mysqli_error($con));
$rowfullview=mysqli_fetch_assoc($resultfullview);
$sqlproductname="SELECT name FROM product WHERE product_id='$rowfullview[product_id]'";
$resultproductname=mysqli_query($con,$sqlproductname) or die ("Error in sqlproductname" . mysqli_error($con));
$rowproductname=mysqli_fetch_assoc($resultproductname);
?>
<div class="card">
<div class="card-body">
<center><h5 class="card-title">Order Product Full View</h5></center>
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<tr><th>Order ID</th><td><?php echo $rowproductname["name"]; ?></td></tr>
<tr><th>Product ID</th><td><?php echo $rowfullview["product_id"]; ?></td></tr>
<tr><th>Quantity</th><td><?php echo $rowfullview["quantity"]; ?></td></tr>
<tr>
<td colspan="2">
<center>
<a href="index.php?pg=order_product.php&option=view"><button class="btn btn-primary">Go Back</button></a>
<a href="index.php?pg=order_product.php&option=edit&pk1=<?php echo $rowfullview["order_id"]; ?>&pk2=<?php echo $rowfullview["product_id"]; ?>"><button class="btn btn-info">Edit</button></a>
</center>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php
}
else if ($_GET["option"] == "edit")
{
if (isset($_GET["edit_pk1"]))
{
$get_orderid =$_GET["edit_pk1"];
}
else
{
$get_orderid =$_GET["pk1"];
}
$get_productid =$_GET["pk2"];
$sqledit = "SELECT * FROM order_product WHERE order_id ='$get_orderid' AND product_id ='$get_productid'";
$resultedit = mysqli_query($con,$sqledit) or die("Sqlfullview error ".mysqli_error($con));
$rowedit=mysqli_fetch_assoc($resultedit);
?>
<!-- form section start -->
<section class="feature_part padding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card">
<form class="form-horizontal" method="POST" action="">
<div class="card-body">
<center><h4 class="card-title">Edit Order Product</h4></center>
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Order ID</label>
<div class="col-sm-3">
<select class="form-control" id="txtorderid" name="txtorderid" placeholder="Order ID Here" required readonly>
<?php
$sqlload="SELECT Distinct order_id FROM order_product WHERE order_id='$rowedit[order_id]'";
$resultload=mysqli_query($con,$sqlload) or die ("Error in sqlload" . mysqli_error($con));
while( $rowload=mysqli_fetch_assoc($resultload))
{
echo '<option value="'.$rowload["order_id"].'">'.$rowload["order_id"].'</option>';
}
?>
</select>
</div>
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Product ID</label>
<div class="col-sm-3">
<select class="form-control" id="txtproductid" name="txtproductid" placeholder="Product ID Here" required readonly>
<?php
$sqlload="SELECT product_id,name FROM product WHERE product_id='$rowedit[product_id]'";
$resultload=mysqli_query($con,$sqlload) or die ("Error in sqlload" . mysqli_error($con));
while( $rowload=mysqli_fetch_assoc($resultload))
{
echo '<option value="'.$rowload["product_id"].'">'.$rowload["name"].'</option>';
}
?>
</select>
</div>
</div>
<!-- field end -->
<!-- field start -->
<div class="form-group row">
<label for="fname" class="col-sm-3 text-right control-label col-form-label">Quantity</label>
<div class="col-sm-3">
<input type="number" class="form-control" id="txtquantity" name="txtquantity" placeholder="Quantity Here" required value="<?php echo $rowedit["quantity"];?>" onkeypress="return NumberValidation(event)">
</div>
</div>
<!-- field end -->
<!-- button start -->
<div class="form-group row">
<div class="col-sm-12">
<center>
<?php
if (isset($_GET["edit_pk1"]))
{
$address="index.php?pg=order_detail.php&option=fullview&pk=".$get_orderid;
}
else
{
$address="index.php?pg=order_product.php&option=add";
}
?>
<a href ="<?php echo $address; ?>"><input type="button" class="btn btn-primary" id="btngoback" name="btngoback" value="Go back"></a>
<input type="reset" class="btn btn-danger" id="btncancel" name="btncancel" value="Cancel">
<input type="submit" class="btn btn-success" id="btnsavechanges" name="btnsavechanges" value="Save Changes">
</center>
</div>
</div>
<!-- button end -->
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<!-- form section end -->
<?php
}
else if ($_GET["option"] == "delete")
{
if (isset($_GET["edit_pk1"]))
{
$get_orderid =$_GET["edit_pk1"];
}
else
{
$get_orderid =$_GET["pk1"];
}
$get_productid =$_GET["pk2"];
$sqldelete = "DELETE FROM order_product WHERE order_id = '$get_orderid' AND product_id = '$get_productid'";
$resultdelete = mysqli_query($con,$sqldelete) or die ("Error in sqldelete ".mysqli_error($con));
if ($resultdelete)
{
if (isset($_GET["edit_pk1"]))
{
$address="index.php?pg=order_detail.php&option=fullview&pk=".$get_orderid;
}
else
{
$address="index.php?pg=order_product.php&option=add";
}
echo '<script> alert("Record is Deleted");
window.location.href="'.$address.'";</script>';
}
}
}
?>
</body>