/
showBookings.php
64 lines (56 loc) · 2.04 KB
/
showBookings.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
<?php
//Check for request method
if($_SERVER['REQUEST_METHOD'] == 'POST') {
assignCar();
}
else
displayBookings();
//This function accesses databases and sends records as XML
function displayBookings() {
$host;
$user;
$pswd;
$dbnm;
$connection = mysqli_connect($host, $user, $pswd, $dbnm) or die('Failed to connect.');
$searchQuery = "SELECT * FROM bookings where status = 'unassigned'";
$result = mysqli_query($connection, $searchQuery);
$xml = new SimpleXMLElement('<xml/>');
if(mysqli_num_rows($result)>0) {
while($result_array = mysqli_fetch_array($result)) {
$data = $xml->addChild('search');
$data->addChild('bookingNumber',$result_array['bookingNumber']);
$data->addChild('customerName',$result_array['customerName']);
$data->addChild('pickupAddress',$result_array['pickupAddress']);
$data->addChild('suburb',$result_array['suburb']);
$data->addChild('destination',$result_array['destination']);
$data->addChild('phoneNumber',$result_array['contactPhone']);
$data->addChild('pickUpDate',$result_array['pickUpDate']);
$data->addChild('pickUpTime',$result_array['pickUpTime']);
$data->addChild('bookingDate',$result_array['bookingDate']);
$data->addChild('bookingTime',$result_array['bookingTime']);
}
}
echo $xml->asXML();
}
//This function assigns car to the booking
function assignCar() {
$host;
$user;
$pswd;
$dbnm;
$chosenBookingNumber = $_POST['chosenBookingNumber'];
$connection = mysqli_connect($host, $user, $pswd, $dbnm) or die('Failed to connect.');
$searchQuery = "Select * FROM bookings where bookingNumber ='$chosenBookingNumber'";
$search = mysqli_query($connection, $searchQuery);
$updateQuery = "UPDATE bookings SET status ='assigned' where bookingNumber ='$chosenBookingNumber'";
//Check if input exists in the datababase
if(mysqli_num_rows($search) == 0) {
echo "Booking number like this does not exist in the database!";
}
//Change record status to assigned
else {
$result = mysqli_query($connection, $updateQuery);
echo "The car has been assigned to $chosenBookingNumber!";
}
}
?>