-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreservation.php
More file actions
80 lines (67 loc) · 2.83 KB
/
reservation.php
File metadata and controls
80 lines (67 loc) · 2.83 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="reservation.css">
<title>Flight Reservation</title>
</head>
<body>
<h1>Flight Reservation</h1>
<form action="reservation.php" method="post">
<label for="departure">Departure City:</label>
<select name="departure" id="departure" required>
<option value="istanbul">Istanbul</option>
<option value="paris">Paris</option>
<!-- Add more departure cities as needed -->
</select>
<label for="destination">Destination City:</label>
<select name "destination" id="destination" required>
<option value="newyork">New York</option>
<option value="tokyo">Tokyo</option>
<!-- Add more destination cities as needed -->
</select>
<label for="name">Your Name:</label>
<input type="text" name="name" id="name" required>
<label for="email">Your Email:</label>
<input type="email" name="email" id="email" required>
<button type="submit" name="reserve">Reserve Ticket</button>
</form>
<?php
if (isset($_POST['reserve'])) {
// Retrieve user input
$departureCity = $_POST['departure'];
$destinationCity = $_POST['destination'];
$userName = $_POST['name'];
$userEmail = $_POST['email'];
// Define valid flight routes
$validRoutes = [
'istanbul' => 'newyork', // Flight 1 (Istanbul to New York)
'paris' => 'tokyo', // Flight 2 (Paris to Tokyo)
// Add more valid routes as needed
];
if (array_key_exists($departureCity, $validRoutes) && $validRoutes[$departureCity] === $destinationCity) {
// The selected route is valid
$selectedFlight = "Flight from $departureCity to $destinationCity";
// Connect to your database and insert reservation information
$host = "localhost";
$dbname = "your_database_name";
$user = "your_database_user";
$password = "your_database_password";
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
$query = "INSERT INTO reservations (flight, name, email) VALUES (:flight, :name, :email)";
$stmt = $pdo->prepare($query);
$stmt->execute(['flight' => $selectedFlight, 'name' => $userName, 'email' => $userEmail]);
echo "Reservation successful! You are now booked on $selectedFlight.";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
} else {
// Invalid route selected
echo "Invalid route. Please select a valid flight route.";
}
}
?>
</body>
</html>