-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathview-status.php
117 lines (110 loc) · 3.84 KB
/
view-status.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
<?php
session_start();
include "config/connection.php";
$errors = array('number' => '', 'date' => '', 'final' => '');
$number = $date = '';
$avail_ac = $avail_sleeper = '';
if(isset($_POST['submit'])){
$number = $_POST['number'];
$date = $_POST['date'];
$number = $conn->real_escape_string($number);
$date = $conn->real_escape_string($date);
if(empty($number)){
$errors['number'] = 'Train Number is required';
}
if(empty($date)){
$errors['date'] = 'Date is required';
}
if(! array_filter($errors)){
//CHECK VALID TRAIN
$query1 = "SELECT * FROM train_status WHERE t_number = '$number' AND t_date = '$date'";
$result = $conn->query($query1);
$query2 = "SELECT * FROM train WHERE t_number = '$number' AND t_date = '$date'";
$result2 = $conn->query($query2);
//IF TUPLE FOUND IN TABLE PRINT STATUS
if($result->num_rows > 0){
$row = $result->fetch_object();
$row1 = $result2->fetch_object();
if($row1->num_ac == 0){
$avail_ac = 0;
}
else{
$avail_ac = $row1->num_ac*18 - $row->seats_b_ac;
}
if($row1->num_sleeper == 0){
$avail_sleeper = 0;
}
else{
$avail_sleeper = $row1->num_sleeper*24 - $row->seats_b_sleeper;
}
}
else{
$errors['final'] = 'Train has not been released';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Check Train Status</title>
</head>
<?php include "template/header.php" ?>
<style>
table {
width: 90%;
margin: 0 auto;
font-size: large;
border: 2px solid rgb(120, 120, 120);
}
td {
background-color: #E4F5D4;
border: 2px solid rgb(120, 120, 120);
}
th, td {
font-weight: bold;
border: 2px dotted rgb(120, 120, 120);
padding: 10px;
text-align: left;
}
td {
font-weight: lighter;
}
</style>
<div style="margin-top:200px;">
<form style="padding:50px;" action="view-status.php" method=POST>
<h3 class = "heading">Check Seats Available For Booking</h3>
<label>
<p class="label-txt">TRAIN NUMBER</p>
<input type="number" class="input" min=0 name="number" value="<?php echo htmlspecialchars($number) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['number'])?></p>
</label>
<label>
<p class="label-txt">DATE</p>
<input type="date" class="input" name="date" value="<?php echo htmlspecialchars($date) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['date'])?></p>
</label>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['final'])?></p>
<a href="index.php" class="register">Back</a>
<button type="submit" name="submit" value="submit">Check</button>
<br><br>
<table>
<tr>
<td><h5> Seats In AC Coach </h5></td>
<td><h5><?php echo $avail_ac ?></h5></td>
</tr>
<tr>
<td><h5> Seats In Sleeper Coach</h5></td>
<td><h5><?php echo $avail_sleeper?></h5></td>
</tr>
</table>
</form>
</div>
<?php include "template/footer.php" ?>
</html>