-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy-cart.php
122 lines (104 loc) · 3.52 KB
/
my-cart.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
<?php
include('top_header.php');
echo "<title>My Cart</title>";
include('header.php');
include('connection.php');
?>
<?php
if(isset($_GET['action'])){
$price = $_GET['price'];
if(!isset($_SESSION['login'])){
session_unset();
echo "<script language='javascript'>
document.location='Login.php';
</script>";
}else {
$sql = "INSERT INTO `order_track_history` ( `user_id`,`price`, `status`) VALUES ( '{$_SESSION['uid']}',$price ,'on packing')";
$res = mysqli_query($conn,$sql);
if(!$res){
die("Error in the order track histroy ".mysqli_error($conn));
}
}
$sql = "select MAX(id) as id from order_track_history";
$res = mysqli_query($conn,$sql);
if(!$res){
die("Error in the order track histroy max".mysqli_error($conn));
}
$row = mysqli_fetch_assoc($res);
$odid =$row['id'];
foreach ($_SESSION['cart'] as $key => $value) {
$sql = "INSERT INTO `orders` (`order_id`, `user_id`, `product_id`, `quantity`) VALUES ('{$odid}', '{$_SESSION['uid']}', '{$key}', {$value['quantity']}) ";
$res = mysqli_query($conn,$sql);
if(!$res){
die("Error in the order ".mysqli_error($conn));
}
echo "<script language='javascript'>
alert('scccesfully Updated buying details');
</script>";
$_SESSION['cart']=NULL;
echo "<script language='javascript'>
document.location='product.php';
</script>";
}
// print_r($row);
}
?>
<h1>My Cart </h1>
<center>
<div class="col-sm-10">
<table class="table table-dark">
<thead>
<tr>
<th scope="row">#</th>
<th scope="col">Product Name</th>
<th scope="col">Image</th>
<th scope="col">price</th>
<th scope="col">Quantity</th>
<th scope="col">Sub Totla Price</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_SESSION['cart'])){
$sql = "SELECT * FROM products WHERE id IN(";
foreach($_SESSION['cart'] as $id => $value){
$sql .=$id. ",";
}
$sql=substr($sql,0,-1) . ") ORDER BY id ASC";
$res = mysqli_query($conn,$sql);
if(!$res){
die("Error in connecting to product table".mysqli_error($conn));
}
$x=1;
$subtot=0;
$fulltot=0;
while ($row=mysqli_fetch_assoc($res)) {
$id=$row['id'];
// $id =$_SESSION['cart']['{$id}'];
?>
<tr>
<th scope="row"><?php echo "".$x; ?></th>
<td><?php echo "".$row['product_name']; ?></td>
<td><img src="upload\<?php echo "".$row['product_image']; ?>" style="width:130px; height:80px;" ></div></td>
<td><?php echo "".$prize=$row['product_price']; ?></td>
<td><?php echo "".$qty=$_SESSION['cart'][$id]['quantity'] ;?></td>
<td><?php echo "".$subtot=$qty*$prize; ?></td>
</tr>
<?php $x++;
$fulltot+=$subtot;
} }?>
<th scope="row"></th>
<th scope="col"></th>
<th scope="col"> </th>
<th scope="col"></th>
<th scope="col">Total Payment</th>
<th scope="col"><?php echo "".$fulltot; ?></th>
</tbody>
</table>
<a href="my-cart.php?action=buy&price=<?php echo "".$fulltot; ?>" class="lnk btn btn-primary" type="submit"><i class="icon fa fa-shopping-cart" style="margin-right:10px;"></i>Buy The Products</a>
</div>
</br>
</center>
<?php
include('footer.php');
?>