-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddmovie.php
More file actions
186 lines (140 loc) · 5.14 KB
/
Copy pathaddmovie.php
File metadata and controls
186 lines (140 loc) · 5.14 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
session_start();
include('header.php');
include_once("db_connect.php");
if (empty($_SESSION['user_id'])){
header("Location: login.php");
}
if (!empty($_POST['isbn_input'])) {
$barcode=$_POST['isbn_input'];
//set upc api url
//$url = "http://api.upcdatabase.org/product/".$barcode."?apikey=67BDE043D668B6EE5508863B7441C873";
$url = "https://api.upcitemdb.com/prod/trial/lookup?upc=$barcode";
//call api
$json = file_get_contents($url);
$json = json_decode($json);
//$scantitle=$json->title;
$scantitle = $json->items[0]->title;
$scantitle = trim($scantitle);
//getmoviedb
$movidburl = "https://api.themoviedb.org/3/search/movie?api_key=5a846dc3f5db35f3d5590b415612624c&query=".rawurlencode($scantitle);
$jsondb = file_get_contents($movidburl);
$jsondb = json_decode($jsondb);
$moviedbid = $jsondb->results[0]->id;
$imdburl = "https://api.themoviedb.org/3/movie/".$moviedbid."?api_key=5a846dc3f5db35f3d5590b415612624c";
$jsonimdb = file_get_contents($imdburl);
$jsonimdb = json_decode($jsonimdb);
$imdbid = $jsondb->imdb_id;
echo $imdbid;
}
$error = false;
if (isset($_POST['addmovie'])) {
$movie_title = mysqli_real_escape_string($conn, $_POST['movie_title']);
$releaseyear = mysqli_real_escape_string($conn, $_POST['releaseyear']);
$moviedb_id = mysqli_real_escape_string($conn, $_POST['moviedb_id']);
$imdb_id = mysqli_real_escape_string($conn, $_POST['imdb_id']);
/* rebuild error checking later
if (empty($movie_title)) {
$error = true;
$mtitle_error = "can't be empty";
}
if(empty($releaseyear)) {
$error = true;
$releaseyear_error = "Please Enter Valid Year";
}
if(empty($moviedb_id)) {
$error = true;
$moviedb_id_error = "Password must be minimum of 6 characters";
}
if(empty($imdb_id)) {
$error = true;
$imdb_id_error = "Password and Confirm Password doesn't match";
}
*/
if (!$error) {
//intsert movie record
if(mysqli_query($conn, "INSERT INTO movies(movie_title, releaseyear, moviedb_id, imdb_id) VALUES('" . $movie_title . "','" . $releaseyear . "','" . $moviedb_id . "', '" . $imdb_id . "')")) {
//select movie titles that equal submitted movie title
$result = mysqli_query ($conn,"SELECT * from movies where movie_title = '" . $movie_title . "' ");
//set var movie_id = movie_id from sql search
while ($row = mysqli_fetch_array($result)) {
$movie_id = $row['movie_id'];
}
//add movie to users personal little
mysqli_query($conn,"INSERT INTO user_movie(user_id, movie_id) VALUES('" . $_SESSION['user_id'] . "','" . $movie_id . "')");
//redirect to index page
header("Location:index.php");
exit();
} else {
$error_message = "Error in adding move...Please try again later!";
}
}
}
?>
<?php if ((isset($_SESSION['user_id']) )) { ?>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<div class="form">
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="addmovieform">
<fieldset>
<legend>Add Movie</legend>
<table>
<tr>
<div class="form-group">
<td>
<label for="movie_title">Movie Title</label>
<t/d>
<td>
<input type="text" name="movie_title" placeholder="Movie Title" value="<?php echo (isset($scantitle))?$scantitle:'';?>" required value="<?php if($error) echo $movie_title; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($mtitle_error)) echo $mtitle_error; ?></span>click <a href="scan.php">here</a> to scan barcode
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="releaseyear">Release Year</label>
</td>
<td>
<input input type="number" name="releaseyear" min="1900" max="2099" step="1" value="2020" required value="<?php if($error) echo $releaseyear; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($releaseyear_error)) echo $releaseyear_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="moviedb_id">Moviedb ID</label>
</td>
<td>
<input type="text" name="moviedb_id" placeholder="Enter Moviedb ID" value="<?php echo (isset($moviedbid))?$moviedbid:'';?>" required value="<?php if($error) echo $moviedb_id; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($moviedb_id_error)) echo $moviedb_id_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="imdb_id">IMDB ID</label>
</td>
<td>
<input type="text" name="imdb_id" placeholder="Enter IMDB ID" value="<?php echo (isset($imdbid))?$imdbid:'';?>" required value="<?php if($error) echo $imdb_id; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($imdb_id_error)) echo $imdb_id_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<input type="submit" name="addmovie" value="Add Movie" class="btn btn-primary" />
</td>
</div>
</tr>
</table>
</fieldset>
</form>
</div>
<P>
Click <a href="logout.php">here</a> to logout
<?php } ?>