-
Notifications
You must be signed in to change notification settings - Fork 0
/
displaycart.php
160 lines (145 loc) · 5.24 KB
/
displaycart.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
<?php
include("header.php");
include("dbconnection.php");
if(!isset($_SESSION['customerid']) && !isset($_SESSION['sellerid']))
{
echo "<script>window.location='customerloginpanel.php'; </script>";
}
if($_GET[delid])
{
$sql = "DELETE FROM product_purchase_record WHERE purchase_record_id='$_GET[delid]'";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) >= 1)
{
echo "<script>alert('Product deleted from cart');</script>";
}
}
if(isset($_GET[prodid]))
{
if(isset($_SESSION['customerid']))
{
$sql = "DELETE FROM product_purchase_record WHERE selling_prod_id='$_GET[prodid]' AND status='Pending' AND customer_id='$_SESSION[customerid]'";
$qsql = mysqli_query($con,$sql);
}
if(isset($_SESSION['sellerid']))
{
$sql = "DELETE FROM product_purchase_record WHERE selling_prod_id='$_GET[prodid]' AND status='Pending' AND seller_id='$_SESSION[sellerid]'";
$qsql = mysqli_query($con,$sql);
}
$sql = "INSERT INTO product_purchase_record(product_purchase_bill_id, selling_prod_id,customer_id, quantity, cost, status,seller_id) VALUES ('0','$_GET[prodid]','$_SESSION[customerid]','1','$_GET[prodcost]','Pending','$_SESSION[sellerid]')";
$qsql = mysqli_query($con,$sql);
echo "<script>alert('Product added to the cart');</script>";
}
?>
<main id="main">
<!-- ======= Cta Section ======= -->
<section id="cta" class="cta">
<div class="container">
<div class="text-center" data-aos="zoom-in">
<br><br>
<h3>My Cart</h3>
</div>
</div>
</section><!-- End Cta Section -->
<form id="form1" name="form1" method="post" action="buyproduct.php">
<!-- ======= Contact Section ======= -->
<section id="contact" class="contact">
<div class="container">
<div class="row">
<div class="col-lg-12" data-aos="fade-up" data-aos-delay="100">
<div class="info mt-4 ">
<center><h4>Update your Cart before payment...</h4></center><hr>
<?php
$i=1;
$sql = "SELECT * FROM product_purchase_record where customer_id='$_SESSION[customerid]' AND status='Pending'";
$qsql = mysqli_query($con,$sql);
if(mysqli_num_rows($qsql) == 0)
{
echo "<center>Empty Cart</center>";
}
else
{
?>
<table ID="datatable" class="table table-striped table-bordered" style="width:100%">
<THEAD>
<tr>
<th scope="row"><strong> Select</strong></th>
<th scope="row"><strong> Image</strong></th>
<th><strong> Product detail</strong></th>
<th><strong> Product Cost</strong></th>
<th><strong> Quantity</strong></th>
<th><strong> Total</strong></th>
<th><strong> Delete</strong></th>
</tr>
</THEAD>
<TBODY>
<?php
while($rs = mysqli_fetch_array($qsql))
{
$sql1 = "SELECT * FROM selling_product WHERE selling_prod_id='$rs[selling_prod_id]'";
$qsql1 = mysqli_query($con,$sql1);
$rs1 = mysqli_fetch_array($qsql1);
echo "
<tr>
<td> <input type='checkbox' name='buyingproduct[]' value='$rs[purchase_record_id]' checked></td>
<td> <img src='imgsellingproduct/$rs1[product_img1]' width='75' height='100'></td>
<td> $rs1[product_description]</td>
<td> $rs[cost]</td>
<td> <input type='text' name='productcart' value='$rs[quantity]' size='3' onkeyup='changecost(this.value,$rs[purchase_record_id],$i)' /> $rs1[quantity_type]</td>
<td> <span id='calccost$i'>" . $rs['cost'] * $rs[quantity] ."</span></td>
<td> <a href='displaycart.php?delid=$rs[purchase_record_id]' onclick='return delconfirm()' class='btn btn-danger'>X</a></td>
</tr>";
$i++;
}
?>
</TBODY>
</table>
<?php
}
?>
<hr>
<center>
<input type="submit" name="submit" id="submit" value="Confirm your order" autofocus class="btn btn-success">
</center>
</div>
</div>
</div>
</div>
</section><!-- End Contact Section -->
</form>
</main><!-- End #main -->
<?php
include("footer.php");
?>
<script type="application/javascript">
function changecost(totqty,purchaseid,divid)
{
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("calccost"+divid).innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","ajaxupdatecart.php?totqty="+totqty+"&purchaseid="+purchaseid+"&divid="+divid,true);
xmlhttp.send();
}
function delconfirm()
{
if(confirm("Are you sure want to delete this cart item?") == true)
{
return true;
}
else
{
return false;
}
}
</script>