-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_add.php
162 lines (161 loc) · 4.6 KB
/
movie_add.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!--This page is used to add Movie information-->
<?php
require_once('facilities.php');
page_head('Add Movie Info');
$db_connection = getConnection();
?>
<div class="container">
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<div class="row">
<div class="col-md-12">
<h2>Add Movie Information</h2>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>Movie ID<sup>*</sup>:</h3>
</div>
</div>
<div class="row">
<div class="col-md-6">
<textarea class="searchtext" name = "Movie_id"></textarea>
</div>
<div class="col-md-6">
<h4>Note: Movie ID cannot be <I>NULL</I>!</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>Movie title<sup>*</sup>:</h3>
</div>
</div>
<div class="row">
<div class="col-md-6">
<textarea class="searchtext" name = "Movie_title"></textarea>
</div>
<div class="col-md-6">
<h4>e.g <I>The Titanic</I></h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>Year:</h3>
</div>
</div>
<div class="row">
<div class="col-md-6">
<textarea class="searchtext" name = "Movie_year"></textarea>
</div>
<div class="col-md-6">
<h4>e.g <I>1997</I></h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>Rating:</h3>
</div>
</div>
<div class="row">
<div class="col-md-6">
<textarea class="searchtext" name = "Movie_rating"></textarea>
</div>
<div class="col-md-6">
<h4>e.g <I>PG-13</I></h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>Company:</h3>
</div>
</div>
<div class="row">
<div class="col-md-6">
<textarea class="searchtext" name = "Movie_company"></textarea>
</div>
<div class="col-md-6">
<h4>e.g <I>Drama Film</I></h4>
</div>
</div>
<div class="row">
<input type = "submit" name = "submit_Movie" value = "submit actor/director info">
</div>
</form>
<div class="row">
<h4>
<?php
if($_POST['submit_Movie']){
// first see if the ID is empty or not
$movie_id = $_POST['Movie_id'];
$movie_id = trim($movie_id);
$movie_title = $_POST['Movie_title'];
$title_test = trim($movie_title);
$movie_year = $_POST['Movie_year'];
$movie_year = trim($movie_year);
$movie_rating = $_POST['Movie_rating'];
$movie_rating = trim($movie_rating);
$movie_company = $_POST['Movie_company'];
$movie_company = trim($movie_company);
$badinput = false;
if(empty($movie_id)){
echo "Please specify movie ID!";
$badinput = true;
}
else{
$read = "select * from Movie where id = " . $movie_id . ";";
mysql_query($read, $db_connection);
$affected = mysql_affected_rows($db_connection);
if($affected){
echo "Movie with ID = ". $movie_id . "already exists!";
exit(0);
}
}
if(empty($title_test)){
echo "Please specify movie title!";
exit(0);
}
else{
$movie_title = "'" . $movie_title . "'";
}
if(empty($movie_year)){
$movie_year = "NULL";
}
if(empty($movie_rating)){
$movie_rating = "NULL";
}
else{
$movie_rating = "'" . $movie_rating . "'";
}
if(empty($movie_company)){
$movie_company = "NULL";
}
else{
$movie_company = "'" . $movie_company . "'";
}
if(!$badinput){
$add = "insert into Movie values(" . $movie_id . ", " . $movie_title . ", " . $movie_year . "," . $movie_rating . "," . $movie_company . ");";
//echo $add;
mysql_query($add, $db_connection);
$affected = mysql_affected_rows($db_connection);
if($affected >= 0)
?>
Movie info added!
<?php
if(mysql_errno($db_connection)){
$select = "select * from Movie where id = " . $movie_id . ";";
mysql_query($select, $db_connection);
$affected = mysql_affected_rows($db_connection);
if($affected > 0) echo "Duplicate Movie ID: " . $movie_id . " already exists.";
else echo "Invalid input";
}
}
}
mysql_close($db_connection);
?>
</h4>
</div>
</div>
</div>
<?php
page_foot();
?>