-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbooking.php
63 lines (56 loc) · 2.03 KB
/
booking.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
<?php
include("connect.php");
$bookingData = json_decode(file_get_contents("php://input"));
$transactionID = rand(10000000, 99999999)+time();
$status = null;
if(count($bookingData) > 0)
{
for($i = 0; $i < count($bookingData); $i++)
{
$ticketid = $bookingData[$i]->ticketid;
$userid = $bookingData[$i]->userid;
$busnum = $bookingData[$i]->busnum;
$travel_date = $bookingData[$i]->travel_date;
$seatno = $bookingData[$i]->seatno;
$passenger_name = $bookingData[$i]->passenger_name;
$gender = $bookingData[$i]->gender;
$age = $bookingData[$i]->age;
$action = $bookingData[$i]->action;
if($action=="edit")
{
mysqli_query($con, "UPDATE bookings SET passenger_name='$passenger_name', age='$age', gender='$gender', travel_date='$travel_date', seatno='$seatno' where ticketid='$ticketid'");
if(mysqli_affected_rows($con))
{
$status = true;
}
}
else
{
mysqli_query($con, "INSERT INTO bookings(userid, ticketid,busnum,travel_date,seatno,passenger_name, gender, age, transactionid) VALUES('$userid','$ticketid','$busnum', '$travel_date', '$seatno', '$passenger_name', '$gender', '$age', '$transactionID')");
if(mysqli_affected_rows($con))
{
$status = true;
}
}
}
if($status)
{
if($action === "edit")
{
echo json_encode(["status" => "success", "action" => "edit"]);
}
else
{
echo json_encode(["status" => "success","tid" => $transactionID, "action" => "add"]);
}
}
else
{
echo json_encode(["status" => "error"]);
}
}
else{
echo json_encode(["status" => "error"]);
}
mysqli_close($con);
?>