-
Notifications
You must be signed in to change notification settings - Fork 0
/
createInstructor.php
145 lines (114 loc) · 4.38 KB
/
createInstructor.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
<?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>)
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(
"EmployeeID" => $_POST['EmployeeID'],
"YearsOfExperience" => $_POST['YearsOfExperience'],
);
// create an SQL statement to insert users input
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"Instructor_Instructs",
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 Instructor_Instructs";
$statement = $connection->prepare($sql);
$statement->bindParam(':EmployeeID', $EmployeeID, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
if ($result && $statement->rowCount() > 0) {
echo "<table><tr><th class='border-class'>EmployeeID</th>
<th class='border-class'>YearsOfExperience</th>";
// output data of each row
foreach($result as $row) {
echo "<tr><td class='borderclass'>".$row["EmployeeID"]."</td>
<td class='borderclass'>".$row["YearsOfExperience"]."</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 Instructor']) && $statement) { ?>
> <?php echo $_POST['EmployeeID']; ?> successfully added.
<?php } ?>
<h2 style="color:white;">Instructors</h2>
<form method="post">
<p>
<input type="submit" name = "view" value="ViewInstructors"></p>
<p>
<label for="EmployeeID">EmployeeID</label>
<input type="text" name="EmployeeID" id="EmployeeID">
<label for="YearsOfExperience">Years Of Experience</label>
<input type="text" name="YearsOfExperience" id="YearsOfExperience">
<input type="submit" name="create" value="Create Instructor"></p>
<!-- <p>-->
<!-- <label for="EmployeeIDUp">EmployeeID to Update</label>-->
<!-- <input type="text" name="EmployeeIDUp" id="EmployeeIDUp">-->
<!---->
<!-- <label for="StationNoUp">StationNo to Update</label>-->
<!-- <input type="text" name="StationNoUp" id="StationNoUp">-->
<!---->
<!-- <input type="submit" name = "update" value="Update Lifeguard Assignment">-->
<!-- </p>-->
<!-- -->
<!-- <p>-->
<!-- <label for="EmployeeIDDel">EmployeeID to Delete</label>-->
<!-- <input type="text" name="EmployeeIDDel" id="EmployeeIDDel">-->
<!-- <input type="submit" name = "delete" value="Delete Instructor">-->
<!-- </p>-->
</form>
<a href="createLifeGuard.php">Back to Lifeguard</a>
<a href="indexEmployee.php">Back to Employee Management</a>
<?php include "templates/footer.php"; ?>