-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditDatabase.php
More file actions
145 lines (126 loc) · 3.42 KB
/
Copy patheditDatabase.php
File metadata and controls
145 lines (126 loc) · 3.42 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
<?php
session_start();
require 'databaseConnection.php';
if(!isset($_SESSION['username'])) {
header('Location: login.php');
}
function getGenres() {
global $conn;
$sql = "SELECT DISTINCT genre
FROM movieDatabase
ORDER BY genre ASC";
$stmt = $conn -> prepare($sql);
$stmt -> execute();
return $stmt -> fetchAll();
}
function getRatings() {
global $conn;
$sql = "SELECT DISTINCT rating
FROM movieDatabase
ORDER BY rating ASC";
$stmt = $conn -> prepare($sql);
$stmt -> execute();
return $stmt -> fetchAll();
}
if( isset ($_POST['submit']) ) {
try {
// insert records into userMovies table
$sql = "INSERT INTO userMovies
(title, director, star, genre, rating, length, year)
VALUES
(:title, :director, :star, :genre, :rating, :length, :year)";
$stmt = $conn -> prepare($sql);
$stmt -> execute( array (":title" => $_POST['title'],
":director" => $_POST['director'],
":star" => $_POST['star'],
":genre" => $_POST['genre'],
":rating" => $_POST['rating'],
":length" => $_POST['length'],
":year" => $_POST['year']) );
echo "<div class='adminMessage'> >> Data Submitted for Approval!</div>";
}
catch (PDOException $e) {
echo "ERROR: " . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Movies To Database</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="ourStyles.css">
</head>
<body>
<div id="header"></div>
<div id="nav">
<h3>Members Area</h3>
<a href="movieSearch.php">Home</a><br>
<a href="editDatabase.php">Add to Database</a><br>
<a href="deleteStuff.php">Delete from Database</a><br>
<a href="changePassword.php">Change Password</a><br>
<a href="logout.php">Logout</a>
</div>
<div class="center">
<table id="login"><form method="post">
<tr><td colspan="2">Add A Movie!</td></tr>
<tr>
<td>Title</td>
<td><input size="20" type="text" name="title"></td>
</tr>
<tr>
<td>Director</td>
<td><input size="20" type="text" name="director"></td>
</tr>
<tr>
<td>Featured Star</td>
<td><input size="20" type="text" name="star"></td>
</tr>
<tr>
<td>Genre</td>
<td><select size=1 name="genre">
<option value="-1">Choose A Genre</option>
<?php
$movieGenres = getGenres();
foreach ($movieGenres as $genre) {
echo "<option value='" . $genre['genre'] . "'>" . $genre['genre'] . "</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Rating</td>
<td><select size="1" name="rating">
<option value="-1">Choose A Rating</option>
<?php
$movieRatings = getRatings();
foreach ($movieRatings as $rating) {
echo "<option value='" . $rating['rating'] . "'>" . $rating['rating'] . "</option>";
}
?>
</select></td>
</tr>
<tr>
<td>Length (in total minutes)</td>
<td><input size="20" type="text" name="length"></td>
</tr>
<tr>
<td>Year</td>
<td><select size=1 name="year">
<option value="-1">Choose A Year</option>
<?php
for ($i=2016; $i>1900; $i--) {
echo "<option value='" . $i . "'>" . $i . "</option>";
}
?>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Enter" name="submit"><img src="popcorn-icon.png"></td>
<td><input type="reset" value="Clear"><img src="popcorn-icon.png"></td>
</tr>
</form></table>
</div>
</body>
</html>
<?php $conn = null; ?>