-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateShuttle.php
More file actions
executable file
·153 lines (122 loc) · 4.77 KB
/
createShuttle.php
File metadata and controls
executable file
·153 lines (122 loc) · 4.77 KB
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
149
150
151
152
153
<?php
// Use an HTML form to create a new entry in the Customer table.
// When SUBMIT button pressed, open new PDO (PHP data object) connection,
// then send INSERT SQL statement with the users inputted values
//function printTable(){
// require "config.php";
// require "common.php";
//
// $connection = new PDO($dsn, $username, $password, $options);
//
// $sql = "SELECT *
// FROM Employee_WorksAt";
//
// $EmployeeID = $_POST['EmployeeID'];
//
// $statement = $connection->prepare($sql);
// $statement->bindParam(':EmployeeID', $CustomerID, PDO::PARAM_STR);
// $statement->execute();
//
// $result = $statement->fetchAll();
//}
//
//printTable();
if (isset($_POST['create'])) {
// config.php holds the server information
// change config file to local host (the one you made in Hazra's tutorial)
// common.php maintains special characters used in html that would otherwise
// not be recognized as HTML, by calling method escape(<html>)
// not be recognized as HTML, by calling method escape(<html>)
require "config.php";
require "common.php";
try {
//open connection with information from config.php
$connection = new PDO($dsn, $username, $password, $options);
// create variables from users form inputs. In PHP, values are placed
// into $_POST array
$new_user = array(
"Destination" => $_POST['Destination'],
"DepartureTime" => $_POST['DepartureTime'],
"ArrivalTime" => $_POST['ArrivalTime'],
);
// create an SQL statement to insert users input
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"ShuttleSchedule",
implode(", ", array_keys($new_user)),
":" . implode(", :", array_keys($new_user))
);
// send the SQL to the server
$statement = $connection->prepare($sql);
$statement->execute($new_user);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
} else if (isset($_POST['view'])){
try {
require "config.php";
require "common.php";
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM ShuttleSchedule";
$statement = $connection->prepare($sql);
$statement->bindParam(':Destination', $Destination, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
if ($result && $statement->rowCount() > 0) {
echo "<table><tr>
<th class='border-class'>VehicleType</th>
<th class='borderclass'>Capacity</th></tr>";
// output data of each row
foreach($result as $row) {
echo "<tr><td class='borderclass'>".$row["Destination"]."</td><td class='borderclass'>".$row["DepartureTime"]."</td><td class='borderclass'>".$row["ArrivalTime"]."</td></tr>";}
echo "</table>";
} else {
echo "0 results";
}
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<!-- include website title/headers/etc, a "successfully added" message,
and the input form itself.-->
<?php include "templates/header.php"; ?>
<?php if (isset($_POST['Create Shuttle Schedule']) && $statement) { ?>
> <?php echo $_POST['Destination']; ?> successfully added.
<?php } ?>
<h2 style="color:white;">Shuttle Schedule</h2>
<form method="post">
<p>
<input type="submit" name = "view" value="View Shuttle Schedule Records"></p>
<p>
<label for="Destination">Destination</label>
<input type="text" name="Destination" id="Destination">
<label for="DepartureTime">DepartureTime</label>
<input type="text" name="DepartureTime" id="DepartureTime">
<label for="ArrivalTime">ArrivalTime</label>
<input type="text" name="ArrivalTime" id="ArrivalTime">
<input type="submit" name="create" value="Create Shuttle Schedule Record">
</p>
<!-- <p>-->
<!---->
<!-- <label for="DestinationUp">VehicleType to Update</label>-->
<!-- <input type="text" name="DestinationUp" id="DestinationUp">-->
<!---->
<!-- <label for="DepartureTimeUp">DepartureTime to Update</label>-->
<!-- <input type="text" name="DepartureTimeUp" id="DepartureTimeUp">-->
<!---->
<!-- <label for="ArrivalTimeUp">ArrivalTime to Update</label>-->
<!-- <input type="text" name="ArrivalTimeUp" id="ArrivalTimeUp">-->
<!---->
<!---->
<!-- <input type="submit" name = "update" value="Update Shuttle Schedule Record">-->
<!-- </p>-->
<!---->
<!-- <p>-->
<!-- <label for="DestinationDel">Shuttle Schedule to Delete</label>-->
<!-- <input type="text" name="DestinationDel" id="DestinationDel">-->
<!-- <input type="submit" name = "delete" value="Delete Shuttle Schedule Record">-->
<!-- </p>-->
</form>
<a href="indexTransport.php">Back to Transportation Management</a>