-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzz_confirmpage
218 lines (162 loc) · 6.37 KB
/
zz_confirmpage
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
217
218
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
// Establish a connection to the MySQL server
$host = 'localhost:3307';
$username = 'root';
$password = '';
$dbname = 'testdb';
try {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare and execute the SQL statement to retrieve the user's bookings
$stmt = $conn->prepare("SELECT bookings.id, tours.place, datetour.date, tours.price, numofppl.num_of_people
FROM bookings
JOIN tours ON bookings.tour_id = tours.id
JOIN datetour ON bookings.tour_id = datetour.tour_id
JOIN numofppl ON bookings.tour_id = numofppl.tour_id
WHERE bookings.user_id = :user_id");
$stmt->bindParam(':user_id', $_SESSION['user_id']);
$stmt->execute();
// Fetch the results and display them in the table
while ($row = $stmt->fetch()) {
echo "<tr>";
echo "<td>".$row['place']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['price']."</td>";
echo "<td>".$row['num_of_people']."</td>";
echo "<td>";
echo "<form method='post' action='delete_booking.php'>";
echo "<input type='hidden' name='booking_id' value='".$row['id']."'>";
echo "<button type='submit'>Delete</button>";
<?php
// Establish database connection
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the ID of the booking to be deleted
$id = $_POST['booking_id'];
// Delete the record from the numofppl table that references the booking to be deleted
$sql = "DELETE FROM numofppl WHERE tour_id=(SELECT tour_id FROM bookings WHERE id=".$id.")";
if ($conn->query($sql) === TRUE) {
// Delete the record from the bookings table
$sql = "DELETE FROM bookings WHERE id=".$id;
if ($conn->query($sql) === TRUE) {
// Redirect to index.php with success message
header("Location: index.php?delete=success");
} else {
echo "Error deleting booking: " . $conn->error;
}
} else {
echo "Error deleting booking: " . $conn->error;
}
// Close database connection
$conn->close();
?>
<?php
// Establish database connection
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the ID of the booking to be deleted
$id = $_POST['booking_id'];
// Delete the record from the numofppl table that references the booking to be deleted
$sql = "DELETE FROM numofppl WHERE tour_id=(SELECT tour_id FROM bookings WHERE id=".$id.")";
if ($conn->query($sql) === TRUE) {
// Delete the record from the bookings table
$sql = "DELETE FROM bookings WHERE id=".$id;
if ($conn->query($sql) === TRUE) {
// Get the ID of the tour to be deleted
$tour_id = mysqli_fetch_assoc(mysqli_query($conn, "SELECT tour_id FROM bookings WHERE id=".$id))['tour_id'];
// Delete the record from the tours table
$sql = "DELETE FROM tours WHERE id=".$tour_id;
if ($conn->query($sql) === TRUE) {
// Redirect to index.php with success message
header("Location: index.php?delete=success");
} else {
echo "Error deleting tour: " . $conn->error;
}
} else {
echo "Error deleting booking: " . $conn->error;
}
} else {
echo "Error deleting numofppl record: " . $conn->error;
}
// Close database connection
$conn->close();
?>
---22nd
<main>
<article>
<section class="section blog">
<div class="container">
<h1>Welcome <?php echo $_SESSION['username']; ?>!</h1>
<h2>Tours Available:</h2>
<div class="card-container">
<?php while ($tour = mysqli_fetch_assoc($tours_result)): ?>
<div class="card">
<img src="\abc\pics\<?php echo $tour['id']; ?>.jpg" alt="<?php echo $tour['place']; ?>">
<div class="card-details">
<h3><?php echo $tour['place']; ?></h3>
<p><?php echo $tour['description']; ?></p>
<div class="price">Price: <?php echo $tour['price']; ?></div>
<div class="date">Available date: <?php echo $tour['date']; ?></div>
<form method="POST">
<input type="hidden" name="tour_id" value="<?php echo $tour['id']; ?>">
<button type="submit" class="btn btn-primary">Book Now</button>
</form>
</div>
</div>
<?php endwhile; ?>
</div>
</article>
</main>
===========================================
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php error_reporting(0); ?>
<?php
session_start();
// Step 1: Establish a database connection
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Step 2: Check if the Book Now button has been clicked
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$tour_id = $_POST['tour_id'];
$user_id = $_SESSION['user_id'];
$booking_date = date('Y-m-d');
$num_of_people = $_POST['num_of_people'];
// Step 3: Insert a new booking into the bookings table
$insert_query = "INSERT INTO bookings (user_id, tour_id, booking_date) VALUES ('$user_id', '$tour_id', '$booking_date')";
mysqli_query($conn, $insert_query);
$booking_id = mysqli_insert_id($conn);
$num_of_people_query = "INSERT INTO numofppl (tour_id, num_of_people) VALUES ('$tour_id', '$num_of_people')";
mysqli_query($conn, $num_of_people_query);
$num_of_people_id = mysqli_insert_id($conn);
// Step 5: Update the bookings table with the numofppl id
$update_query = "UPDATE bookings SET numofppl_id = '$num_of_people_id' WHERE id = '$booking_id'";
mysqli_query($conn, $update_query);
}
// Step 4: Retrieve all tours available
$sql = "SELECT tours.id, tours.place, tours.price, tours.description,datetour.date
FROM tours
INNER JOIN datetour ON tours.Id = datetour.tour_id WHERE tours.place = '".$_POST['place']."' AND datetour.date = '".$_POST['tour_date']."'";
$tours_result = mysqli_query($conn, $sql);
// Step 6: Redirect the user to the payment page
// Step 6: Redirect the user to the payment page
header("Location: payments.php");
exit();
?>