-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtyPhp.php
113 lines (75 loc) · 2.03 KB
/
qtyPhp.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
<?php
SESSION_START();
$productType = $_REQUEST['type'];
$qty = $_REQUEST['value'];
$email = $_SESSION['email'];
$emailcart = "cart$email";
$emailqty = "qty$email";
if (!isset($_SESSION["$emailqty"])) {
$_SESSION["$emailqty"] = array();
}
$price = 0;
$found = false;
for ($z = 0;$z < sizeof($_SESSION["$emailcart"]);$z++ ){
if ($_SESSION["$emailcart"][$z][0] == $productType){
$_SESSION["$emailcart"][$z][2];
$_SESSION["$emailcart"][$z][2] = $_SESSION["$emailcart"][$z][2] + $qty;
$prodName = $_SESSION["$emailcart"][$z][1];
$price = $_SESSION["$emailcart"][$z][3] * $_SESSION["$emailcart"][$z][2];
$_SESSION["$emailcart"][$z][3] = $price;
$found = true;
}
}
if (!($found)) {
exit();
}
$status = false;
if (sizeof($_SESSION["$emailqty"]) != 0){
for ($q = 0;$q < sizeof($_SESSION["$emailqty"]);$q++){
if ($_SESSION["$emailqty"][$q][0] == $productType){
$_SESSION["$emailqty"][$q][1] = $_SESSION["$emailqty"][$q][1] + $qty;
$status = true;
}
}
}
if(sizeof($_SESSION["$emailqty"]) == 0){
$_SESSION["$emailqty"][0][0] = $productType;
$_SESSION["$emailqty"][0][1] = $qty;
$status = true;
}
if ($status != true){
$number = sizeof($_SESSION["$emailqty"]);
$_SESSION["$emailqty"][$number][0] = $productType;
$_SESSION["$emailqty"][$number][1] = $qty;
}
?>
<html>
<body>
<table border="1" style = "margin: auto;width: 80%;border-collapse: collapse;" >
<caption>Your cart : </caption>
<thead>
<tr>
<th>Product Type</th>
<th>Product Name </th>
<th>Qty</th>
<th>Price </th>
</tr>
</thead>
<tbody>
<?php
$x = 0;
$c = 0;
for ($c = 0;$c < sizeof($_SESSION["$emailcart"]);$c++){
?> <tr> <?php
for ($x = 0;$x < sizeof($_SESSION["$emailcart"][0]);$x++){
?>
<td><?php echo $_SESSION["$emailcart"][$c][$x]; ?></td>
<?php
}
?> </tr><?php echo "\n";
}
?>
</tbody>
</table>
</body>
</html>