-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocessMask.php
159 lines (134 loc) · 3.16 KB
/
processMask.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
<?php
include_once 'includes/covaid_database.php';
$colorP = $_POST['mask_primary_color'];
$colorS = $_POST['mask_secondary_color'];
$image = $_POST['images'];
$product_id=4;
$product_Qty=1;
$product_name="Custom Mask";
$sql = "SELECT * FROM products";
$retval = mysqli_query( $conn,$sql);
if(! $retval ) {
die('Could not get data: ' . mysqli_error());
}
$result=mysqli_num_rows($retval);
if($result>0){
while ( $row = mysqli_fetch_assoc($retval)){
if($row["id"]==61){
$special=$row['specialPrice'];
$product_price=$row['price'];
break;
}
}
}
if($special!=null||$special<0){
$product_price=$special;
}
//Insert product into products table to get ID
$sql = "INSERT INTO products (name, price)
VALUES('$product_name', '$product_price');";
mysqli_query($conn, $sql);
$product_id = mysqli_insert_id($conn);
$sql ="DELETE FROM products WHERE id='$product_id' ";
mysqli_query($conn, $sql);
//Assign primary color
switch($colorP){
case 1:
$colorP="red";
break;
case 2:
$colorP="blue";
break;
case 3:
$colorP="green";
break;
case 4:
$colorP="pink";
break;
case 5:
$colorP="yellow";
break;
case 6:
$colorP="purple";
break;
case 7:
$colorP="orange";
break;
case 8:
$colorP="black";
break;
case 9:
$colorS="white";
break;
}
//Assign secondary color
switch($colorS){
case 1:
$colorS="red";
break;
case 2:
$colorS="blue";
break;
case 3:
$colorS="green";
break;
case 4:
$colorS="pink";
break;
case 5:
$colorS="yellow";
break;
case 6:
$colorS="purple";
break;
case 7:
$colorS="orange";
break;
case 8:
$colorS="black";
break;
case 9:
$colorS="white";
break;
}
//Assign image
switch($image){
case 1:
$image="images/animal/elephant.png";
break;
case 2:
$image="images/animal/fox.png";
break;
case 3:
$image="images/animal/gecko.png";
break;
case 4:
$image="images/animal/polarbear.png";
break;
case 5:
$image="images/animal/rabbit.png";
break;
case 6:
$image="images/animal/no_image_selected.png";
break;
}
$sql="SELECT * FROM cart WHERE id=$product_id";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
//Check if this product is already in cart
if ($resultCheck > 0) {
$row = mysqli_fetch_assoc($result);
//update quantity
$oldQty=$row["quantity"];
$product_Qty=$oldQty+$product_Qty;
$sql="UPDATE cart SET quantity='$product_Qty' WHERE id='$product_id'";
mysqli_query($conn, $sql);
}
//If it's not in the cart
else{
$sql = "INSERT INTO cart (id, productName, quantity, price, image, maskPColor, MaskSColor)
VALUES('$product_id', '$product_name', '$product_Qty', '$product_price','$image','$colorP','$colorS');";
mysqli_query($conn, $sql);
}
header("Location: shoppingCart.php")
?>