-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooktickets.php
202 lines (151 loc) · 5.06 KB
/
booktickets.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
<?php
include 'db.php';
session_start();
$userId = $_GET["userId"];
$showId = $_GET["showId"];
$seats = $_GET["seats"];
$prices = $_GET["prices"];
$types = $_GET["types"];
//Extracting data from the table movie_show
$sql = "SELECT movie_id, date, time, screen_id FROM movie_show WHERE show_id=$showId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$movieId = $row['movie_id'];
$show_date = $row['date'];
$date = date_create($show_date);
$date = date_format($date, "l, j M Y");
$show_time = $row['time'];
$time = date_create($show_date. " ". $show_time);
$time = date_format($time, "h:i A");
$screenId = $row['screen_id'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Extracting data from the table movie
$sql = "SELECT name, language, age_certificate, format, runtime FROM movie WHERE movie_id=$movieId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$movie_name = $row['name'];
$language = $row['language'];
$format = $row['format'];
$runtime = $row['runtime'];
$age_certificate = $row['age_certificate'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Extracting data from the table screen
$sql = "SELECT name, theatre_id, seat_map FROM screen WHERE screen_id=$screenId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$screen_name = $row['name'];
$theatreId = $row['theatre_id'];
$seatmap = $row['seat_map'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Extracting data from the table theatre
$sql = "SELECT name FROM theatre WHERE theatre_id=$theatreId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$theatre_name = $row['name'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
$seatArray = array();
$priceArray = array();
$typeArray = array();
$flag=0;
$len = strlen($seats);
$start = 0;
while($flag==0)
{
$commaIndex = strpos($seats, ",", $start);
if($commaIndex == false)
{
$flag=1;
$commaIndex = $len;
}
$seat = substr($seats,$start,$commaIndex-$start);
$start = $commaIndex+1;
array_push($seatArray, $seat);
}
$flag=0;
$len = strlen($prices);
$start = 0;
while($flag==0)
{
$commaIndex = strpos($prices, ",", $start);
if($commaIndex == false)
{
$flag=1;
$commaIndex = $len;
}
$price = (int)substr($prices,$start,$commaIndex-$start);
$start = $commaIndex+1;
array_push($priceArray, $price);
}
$flag=0;
$len = strlen($types);
$start = 0;
while($flag==0)
{
$commaIndex = strpos($types, ",", $start);
if($commaIndex == false)
{
$flag=1;
$commaIndex = $len;
}
$type = substr($types,$start,$commaIndex-$start);
$start = $commaIndex+1;
array_push($typeArray, $type);
}
//$sql = "INSERT INTO ticket VALUES (NULL,'$seat','$screen','$theatre','$movie','$date','$time','$show_id')";
//$result = $conn->query($sql);
$len = count($seatArray);
$amount = 0;
for($i=0; $i<$len; $i++) {
$amount += $priceArray[$i];
}
date_default_timezone_set('Asia/Kolkata');
$time_of_booking = date("Y-m-d H:i:s");
//Putting data into the table transaction
$sql = "INSERT INTO transaction (amount, time_of_booking, number_of_tickets, movie_name, screen_name, theatre_name, show_date, show_time, show_id, user_id) VALUES ($amount, '$time_of_booking', $len, '$movie_name', '$screen_name', '$theatre_name', '$show_date', '$show_time', $showId, $userId)";
if(!mysqli_query($conn, $sql)) {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Getting the transaction_id of the transaction
$transaction_id = 0;
$sql = "SELECT transaction_id FROM transaction WHERE time_of_booking='$time_of_booking'";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$transaction_id = $row['transaction_id'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Putting data into the table ticket
for($i=0; $i<$len; $i++) {
$sql = "INSERT INTO ticket (seat_number, seat_type, price, transaction_id, show_id) VALUES ('$seatArray[$i]', '$typeArray[$i]', $priceArray[$i], $transaction_id, $showId)";
if(!mysqli_query($conn, $sql)) {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
}
mysqli_close($conn);
echo "
<div id='ticket'>
<h2>Tickets booked successfully!</h2>
<p id='transaction'>Transaction ID: $transaction_id</p>
<p>$movie_name ($language $format) ($age_certificate)</p>
<p>$theatre_name $screen_name</p>
<p>$date $time</p>
<p>Total Amount ₹$amount</p>
<p>";
for($i=0; $i<$len; $i++) {
echo "$seatArray[$i] ($typeArray[$i])<br>";
}
echo "</p></div>";
?>