-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomepage.php
217 lines (159 loc) · 7.05 KB
/
homepage.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
<?php
session_start();
// If user directly open homepage url without login, it will redirect to index.html.
if($_SESSION['userid'] == ''){
header("Location: index.html");
die();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="./homepage.css">
<link rel="stylesheet" href="./#.css">
<title>Railway System</title>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg bg-success shadow ">
<div class="container ">
<a class="navbar-brand " href="#">
<img src="./images/logo.png" alt="RailwayLogo" width="60">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./profile.php">My Profile</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="./booking.php">Booking</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- ------------------------ -->
<!-- Form -->
<div class="global-container">
<div class="card login-form">
<div class="card-body mycard mt-5">
<h3 class="card-title text-center">Book your Train Tickets</h3>
<div class="card-text">
<!-- <h1></h1> -->
<form class="d-flex justify-content-around flex-wrap " action="" method="POST">
<div class="form-group mt-1 col-10 col-sm-10">
<label for="fromLocation">From</label>
<input type="text" class=" d-inline form-control w-100" id="fromLocation"
aria-describedby="emailHelp" name="fromcity" required>
</div>
<div class="form-group mt-4 col-10 col-sm-10 ">
<label for="destination">To</label>
<input type="text" class="d-inline form-control w-100" id="destination" name="destcity" required>
</div>
<div class="form-group mt-4 col-10 col-sm-10">
<label for="mydate">Date</label>
<input type="date" class="d-inline form-control w-100" id="mydate" name="bookdate" required>
</div>
<div class="form-group mt-4 col-10 col-sm-10">
<label for="forquantity">Ticket Quantity <i>( Min: 1 or Max: 5 )</i> </label>
<input type="number" class="d-inline form-control w-100" id="forquantity" onchange="fareAmount()" name="quantity" min="1" max="5" required>
</div>
<div class="form-group mt-4 col-10 col-sm-10">
<label for="fornumber">Fare Amount</label>
<input type="number" class="d-inline form-control w-100" id="fornumber" name="amount" readonly required value="">
</div>
<input type="submit" name="book" class="btn btn-primary btn-block col-3 col-sm-3 mt-4 mb-2" value="Book your train"/>
</form>
</div>
</div>
</div>
</div>
<!-- ------------------------------- -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa"
crossorigin="anonymous"></script>
<script>
function fareAmount(){
let fromLocation = document.getElementById('fromLocation').value;
let destination = document.getElementById('destination').value;
let quantity = document.getElementById('forquantity');
let fare = document.getElementById('fornumber');
if ((fromLocation == "Karachi" && destination == "Lahore")|| (fromLocation == "Lahore" && destination == "Karachi")) {
fare.value = 5500 * quantity.value;
}
else if((fromLocation == "Karachi" && destination == "Islamabad") || (fromLocation == "Islamabad" && destination == "Karachi")){
fare.value = 7000 * quantity.value;
}
else if((fromLocation == "Karachi" && destination == "Rawalpindi") || (fromLocation == "Rawalpindi" && destination == "Karachi")){
fare.value = 8000 * quantity.value;
}
else if((fromLocation == "Karachi" && destination == "Peshawar") || (fromLocation == "Peshawar" && destination == "Karachi")){
fare.value = 9500 * quantity.value;
}
else if((fromLocation == "Karachi" && destination == "Hyderabad") || (fromLocation == "Hyderabad" && destination == "Karachi")){
fare.value = 1500 * quantity.value;
}
else if((fromLocation == "Lahore" && destination == "Islamabad") || (fromLocation == "Islamabad" && destination == "Lahore")){
fare.value = 3000 * quantity.value;
}
else if((fromLocation == "Lahore" && destination == "Rawalpindi") || (fromLocation == "Rawalpindi" && destination == "Lahore")){
fare.value = 3500 * quantity.value;
}
else if((fromLocation == "Lahore" && destination == "Multan") || (fromLocation == "Multan" && destination == "Lahore")){
fare.value = 4000 * quantity.value;
}
else if((fromLocation == "Lahore" && destination == "Peshawar") || (fromLocation == "Peshawar" && destination == "Lahore")){
fare.value = 6000 * quantity.value;
}
else{
alert("Train not available on selected routes.")
}
console.log(fromLocation);
}
</script>
</body>
</html>
<?php
include('config.php');
if(isset($_POST['book'])){
$fromCity = $_POST['fromcity'];
$destCity = $_POST['destcity'];
$bookingDate = $_POST['bookdate'];
$ticketQuantity = $_POST['quantity'];
$fareAmount = $_POST['amount'];
$homeUserID = $_SESSION['userid'];
$bookinginsertquery = "INSERT INTO booking(booking_id, from_city, destination_city, book_date, booking_status, quantity, amount, user_id) VALUES (NULL,'$fromCity','$destCity','$bookingDate','pending',$ticketQuantity, $fareAmount, $homeUserID)" ;
$bookingResult = mysqli_query($conn, $bookinginsertquery);
if($bookingResult){
?>
<script>
alert("Booking Successfull");
location.href = 'payment.php';
</script>
<?php
}
else{
?>
<script>
alert("Oops There some error!");
</script>
<?php
}
}
?>