-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_ticket_details_form_handler.php
148 lines (137 loc) · 4.78 KB
/
add_ticket_details_form_handler.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
<?php
session_start();
?>
<html>
<head>
<title>Add Ticket Details</title>
</head>
<body>
<?php
$i=1;
if(isset($_POST['Submit']))
{
$pnr=rand(1000000,9999999);
$date_of_res=date("Y-m-d");
$flight_no=$_SESSION['flight_no'];
$journey_date=$_SESSION['journey_date'];
$class=$_SESSION['class'];
$booking_status="PENDING";
$no_of_pass=$_SESSION['no_of_pass'];
$lounge_access=$_POST['lounge_access'];
$priority_checkin=$_POST['priority_checkin'];
$insurance=$_POST['insurance'];
$total_no_of_meals=0;
$_SESSION['pnr']=$pnr;
$_SESSION['lounge_access']=$lounge_access;
$_SESSION['priority_checkin']=$priority_checkin;
$_SESSION['insurance']=$insurance;
$payment_id=NULL;
$customer_id=$_SESSION['login_user'];
require_once('Database Connection file/mysqli_connect.php');
if($_SESSION['class']=='economy')
{
$query="SELECT price_economy FROM Flight_Details where flight_no=? and departure_date=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ss",$flight_no,$journey_date);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$ticket_price);
mysqli_stmt_fetch($stmt);
}
else if($_SESSION['class']=='business')
{
$query="SELECT price_business FROM Flight_Details where flight_no=? and departure_date=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ss",$flight_no,$journey_date);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$ticket_price);
mysqli_stmt_fetch($stmt);
}
mysqli_stmt_close($stmt);
$ff_mileage=$ticket_price/10;
$query="INSERT INTO Ticket_Details (pnr,date_of_reservation,flight_no,journey_date,class,booking_status,no_of_passengers,lounge_access,priority_checkin,insurance,payment_id,customer_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ssssssisssss",$pnr,$date_of_res,$flight_no,$journey_date,$class,$booking_status,$no_of_pass,$lounge_access,$priority_checkin,$insurance,$payment_id,$customer_id);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
echo $affected_rows.'<br>';
// mysqli_stmt_bind_result($stmt,$cnt);
// mysqli_stmt_fetch($stmt);
// echo $cnt;
/*
$response=@mysqli_query($dbc,$query);
*/
if($affected_rows==1)
{
echo "Successfully Submitted<br>";
}
else
{
echo "Submit Error";
echo mysqli_error();
}
for($i=1;$i<=$no_of_pass;$i++)
{
echo "frequent_flier_no=".$_POST['pass_ff_id'][$i-1].'<br>';
if($_POST['pass_ff_id'][$i-1]=='')
$_POST['pass_ff_id'][$i-1]=NULL;
else
{
$query="SELECT count(*) from Customer c, Frequent_Flier_Details f WHERE c.name=? and f.frequent_flier_no=? and c.customer_id=f.customer_id";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"ss",$_POST['pass_name'][$i-1],$_POST['pass_ff_id'][$i-1]);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
mysqli_stmt_bind_result($stmt,$cnt);
mysqli_stmt_fetch($stmt);
echo "cnt=".$cnt."<br>";
mysqli_stmt_close($stmt);
if($cnt==1)
{
$query="UPDATE Frequent_Flier_Details SET mileage=mileage+? where frequent_flier_no=?";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"is",$ff_mileage,$_POST['pass_ff_id'][$i-1]);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
echo $affected_rows.'<br>';
mysqli_stmt_close($stmt);
}
}
$query="INSERT INTO Passengers (passenger_id,pnr,name,age,gender,meal_choice,frequent_flier_no) VALUES (?,?,?,?,?,?,?)";
$stmt=mysqli_prepare($dbc,$query);
if($_POST['pass_meal'][$i-1]=='yes')
$total_no_of_meals++;
mysqli_stmt_bind_param($stmt,"ississs",$i,$pnr,$_POST['pass_name'][$i-1],$_POST['pass_age'][$i-1],$_POST['pass_gender'][$i-1],$_POST['pass_meal'][$i-1],$_POST['pass_ff_id'][$i-1]);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
echo 'Passenger added '.$affected_rows.'<br>';
// mysqli_stmt_bind_result($stmt,$cnt);
// mysqli_stmt_fetch($stmt);
// echo $cnt;
}
$_SESSION['total_no_of_meals']=$total_no_of_meals;
mysqli_stmt_close($stmt);
mysqli_close($dbc);
header("location: payment_details.php");
// else
// {
// echo "Submit Error";
// echo mysqli_error();
// }
// }
// else
// {
// echo "The following data fields were empty! <br>";
// foreach($data_missing as $missing)
// {
// echo $missing ."<br>";
// }
// }
// }
}
else
{
echo "Submit request not received";
}
?>
</body>
</html>