-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOUPON.php
216 lines (185 loc) · 5.91 KB
/
COUPON.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
<?php
// Include your database connection file here
include("connection.php");
// Start a PHP session if not already started
session_start();
// Initialize userCredits to 0
$userCredits = 0;
// Check if the user is logged in
if (isset($_SESSION["username"])) {
$user_name = $_SESSION["username"];
// Prepare and execute a SQL query to fetch the user's credit points
$sql = "SELECT credit FROM credit WHERE user_name = '$user_name'";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s",$user_name);
$stmt->execute();
$stmt->bind_result($userCredits);
// Fetch the user's credit points
if ($stmt->fetch()) {
// User's credit points were fetched successfully
} else {
// User not found in the credit table, initialize with 0 credits
$userCredits = 0;
}
// Close the prepared statement
$stmt->close();
}
// Check if a coupon has been redeemed
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["coupon-credit"])) {
$couponCredit = 20;
// Check if the user has enough credits to redeem the coupon
if ($userCredits >= $couponCredit) {
// Deduct the coupon credit from the user's total credits
$userCredits -= $couponCredit;
// Update the user's credit in the database
$updateSql = "UPDATE credit SET credit = '$userCredits' WHERE user_name ='$user_name'";
$updateStmt = $conn->prepare($updateSql);
$updateStmt->bind_param("si",$user_name,$userCredits);
$updateStmt->execute();
// Close the update statement
$updateStmt->close();
// Provide a success message
$redeemMessage = "You have successfully redeemed the coupon! Your remaining credits: " . $userCredits;
} else {
// Provide an error message for insufficient credits
$redeemMessage = "Insufficient credits to redeem this coupon.";
}
}
// Close the database connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tourist Coupons</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f0ecec;
}
header {
background-color: #000000;
color: #fff;
text-align: center;
padding: 20px 0;
}
h1 {
font-size: 36px;
}
main {
width: 100%;
height:auto;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
border-radius: 5px;
}
.coupon-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.coupon {
background-color: #fff;
padding: 20px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 5px;
width: calc(33.33% - 20px);
text-align: center;
}
.coupon img {
max-width: 100%;
height: 100px;
margin-bottom: 10px;
}
h2 {
font-size: 16px;
margin-bottom: 10px;
font-weight:bold;
}
p {
font-size: 12px;
margin-bottom: 10px;
font-weight:bold;
}
.redeem-btn {
background-color: #007acc;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.redeem-btn:hover {
background-color: #005b99;
}
.user-info {
margin-top: 20px;
text-align: center;
}
.user-info h2 {
font-size: 20px;
}
.user-info #user-credits {
font-weight: bold;
font-size: 24px;
color: #007acc;
}
</style>
</head>
<body>
<header>
<h1>Tourist Coupons</h1>
</header>
<main>
<section class="coupon-container">
<div class="coupon">
<img src="logo.jpeg" alt="Coupon 1">
<h2>Assam Coupon</h2>
<p>Credit Points: 20</p>
<form method="POST" action="COUPON.php">
<input type="hidden" name="coupon-credit" value="20">
<button type="submit" class="redeem-btn"><a href="coupancode1.html">Redeem</a></button>
</form>
</div>
</section>
<section class="user-info">
<h2>Your Credits: <span id="user-credits"><?php echo $userCredits; ?></span></h2>
</section>
<section class="redeem-message">
<?php if (isset($redeemMessage)) { echo $redeemMessage; } ?>
</section>
</main>
<!--<script>
const redeemButtons = document.querySelectorAll('.redeem-btn');
const userCreditsSpan = document.getElementById('user-credits');
let userCredits = 0;
redeemButtons.forEach((button) => {
button.addEventListener('click', () => {
const creditPoints = parseInt(button.getAttribute('data-credit'));
if (userCredits >= creditPoints) {
userCredits -= creditPoints;
updateUserCredits();
alert(`You have successfully redeemed the coupon! Your remaining credits: ${userCredits}`);
} else {
alert('Insufficient credits to redeem this coupon.');
}
});
});
function updateUserCredits() {
userCreditsSpan.textContent = userCredits;
}
updateUserCredits();
</script>-->
</body>
</html>