-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateVehicles.php
More file actions
executable file
·166 lines (131 loc) · 4.91 KB
/
createVehicles.php
File metadata and controls
executable file
·166 lines (131 loc) · 4.91 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
154
155
156
157
158
159
160
161
162
163
164
165
166
<?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(
"VehicleType" => $_POST['VehicleType'],
"Capacity" => $_POST['Capacity'],
);
// create an SQL statement to insert users input
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"Vehicle",
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 Vehicle";
$statement = $connection->prepare($sql);
$statement->bindParam(':VehicleType', $VehicleType, 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["VehicleType"]."</td><td class='borderclass'>".$row["Capacity"]."</td></tr>";}
echo "</table>";
} else {
echo "0 results";
}
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
} else if (isset($_POST['delete'])) {
try {
require "config.php";
require "common.php";
$connection = new PDO($dsn, $username, $password, $options);
$CustomerID = $_POST['CustomerID_del'];
$sql = "DELETE FROM Customer WHERE CustomerID = $CustomerID";
$statement = $connection->prepare($sql);
$statement->bindValue(':CustomerID_del', $CustomerID);
$statement->execute();
$success = "User successfully deleted";
} 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 VehicleType Record']) && $statement) { ?>
> <?php echo $_POST['VehicleType']; ?> successfully added.
<?php } ?>
<h2 style="color:white;">VehicleType Record</h2>
<form method="post">
<p>
<input type="submit" name = "view" value="View Vehicle Records"></p>
<p>
<label for="VehicleType">VehicleType</label>
<input type="text" name="VehicleType" id="VehicleType">
<label for="Capacity">Destination</label>
<input type="text" name="Capacity" id="Capacity">
<input type="submit" name="create" value="Create Vehicle Record">
</p>
<!-- <p>-->
<!---->
<!-- <label for="VehicleTypeUp">VehicleType to Update</label>-->
<!-- <input type="text" name="VehicleTypeUp" id="VehicleTypeUp">-->
<!---->
<!-- <label for="CapacityUp">Destination to Update</label>-->
<!-- <input type="text" name="CapacityUp" id="CapacityUp">-->
<!---->
<!---->
<!-- <input type="submit" name = "update" value="Update Vehicle Record">-->
<!-- </p>-->
<!-- -->
<!-- <p>-->
<!-- <label for="VehicleTypeDel">VehicleType to Delete</label>-->
<!-- <input type="text" name="VehicleTypeDel" id="VehicleTypeDel">-->
<!-- <input type="submit" name = "delete" value="Delete VehicleType Record">-->
<!-- </p>-->
<!-- -->
</form>
<a href="indexTransport.php">Back to Transportation Management</a>