-
Notifications
You must be signed in to change notification settings - Fork 36
/
booktkt.php
100 lines (100 loc) · 2.71 KB
/
booktkt.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
<?php
session_start();
if(empty($_SESSION['user_info'])){
echo "<script type='text/javascript'>alert('Please login before proceeding further!');</script>";
}
$conn = mysqli_connect("localhost","root","","railway");
if(!$conn){
echo "<script type='text/javascript'>alert('Database failed');</script>";
die('Could not connect: '.mysqli_connect_error());
}
if (isset($_POST['submit']))
{
$trains=$_POST['trains'];
$sql = "SELECT t_no FROM trains WHERE t_name = '$trains'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$email=$_SESSION['user_info'];
$query="UPDATE passengers SET t_no='$row[t_no]' WHERE email='$email';";
if(mysqli_query($conn, $query))
{
$message = "Ticket booked successfully";
}
else {
$message="Transaction failed";
}
echo "<script type='text/javascript'>alert('$message');</script>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Book a ticket</title>
<LINK REL="STYLESHEET" HREF="STYLE.CSS">
<style type="text/css">
#booktkt {
margin:auto;
margin-top: 50px;
width: 40%;
height: 60%;
padding: auto;
padding-top: 50px;
padding-left: 50px;
background-color: rgba(0,0,0,0.3);
border-radius: 25px;
}
html {
background: url(img/bg7.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#journeytext {
color: white;
font-size: 28px;
font-family:"Comic Sans MS", cursive, sans-serif;
}
#trains {
margin-left: 90px;
font-size: 15px;
}
#submit {
margin-left: 150px;
margin-bottom: 40px;
margin-top: 30px
}
</style>
<script type="text/javascript">
function validate() {
var trains=document.getElementById("trains");
if(trains.selectedIndex==0)
{
alert("Please select your train");
trains.focus();
return false;
}
}
</script>
</head>
<body>
<?php
include ('header.php');
?>
<div id="booktkt">
<h1 align="center" id="journeytext">Choose your journey</h1><br/><br/>
<form method="post" name="journeyform" onsubmit="return validate()">
<select id="trains" name="trains" required>
<option selected disabled>-------------------Select trains here----------------------</option>
<option value="rajdhani" >Rajdhani Express - Mumbai Central to Delhi</option>
<option value="duronto" >Duronto Express - Mumbai Central to Ernakulum</option>
<option value="geetanjali">Geetanjali Express - CST to Kolkata</option>
<option value="garibrath" >Garib Rath - Udaipur to Jammu Tawi</option>
<option value="mysoreexp" >Mysore Express - Talguppa to Mysore Jn</option>
</select>
<br/><br/>
<input type="submit" name="submit" id="submit" class="button" />
</form>
</div>
</body>
</html>