-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_comment.php
182 lines (180 loc) · 4.65 KB
/
movie_comment.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!--This page is used to add movie comments-->
<?php
require_once('facilities.php');
page_head('Movie Comment');
$db_connection = getConnection();
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Movie Comment</h2>
</div>
</div>
<?php
$movieID = $_GET['Movie_id'];
if(empty($movieID)){
$noInputMovieID = true;
}
else{
$noInputMovieID = false;
$action = $_SERVER['PHP_SELF'] . "?Movie_id=" . $movieID;
}
if($noInputMovieID){
?>
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<?php
}
else{
?>
<form method = "POST" action = "<?php echo $action;?>">
<?php
}
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>Name:</h3>
</div>
</div>
<div class="row">
<div class="col-md-4">
<textarea name = "Review_name"></textarea>
</div>
<div class="col-md-4">
<h4>e.g <I>Skyfans</I></h4>
</div>
</div>
<!--time should not be a input value-->
<!--if it is linked from movie info page, then it should not have movie id input box-->
<?php
if($noInputMovieID){
?>
<div class="row">
<div class="col-md-12">
<h3>ID of Movie:</h3>
</div>
</div>
<div class="row">
<div class="col-md-4">
<textarea name = "Review_id"></textarea>
</div>
<div class="col-md-4">
<h4>e.g <I>111111</I></h4>
</div>
</div>
<?php
}
// must be a numberic
?>
<div class="row">
<div class="col-md-12">
<h3>Rating:</h3>
</div>
</div>
<div class="row">
<div class="col-md-4">
<textarea name = "Review_rating"></textarea>
</div>
<div class="col-md-4">
<h4>In range of <I>0 - 5</I></h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3>Comment:</h3>
</div>
</div>
<div class="row">
<div class="col-md-4">
<textarea id="movie-comment" name = "Review_comment"></textarea>
</div>
<div class="col-md-8">
<h4>Note: the comment cannot have more than 500 characters!</h4>
</div>
</div>
<div class="row">
<input type = "submit" name = "submit_review" value = "submit movie comments">
</div>
</form>
<div class="row">
<h4>
<?php
if($_POST['submit_review']){
$name = $_POST['Review_name'];
$name = trim($name);
$ID = $_GET['Movie_id'];
$ID = trim($ID);
if(empty($ID)){
$noInputMovieID = true;
}
else{
$noInputMovieID = false;
}
if($noInputMovieID){
$ID = $_POST['Review_id'];
}
$time = "'" . Date("Y-m-d H:i:s") . "'";
$rating = $_POST['Review_rating'];
$rating = trim($rating);
$comments = $_POST['Review_comment'];
$test = trim($comments);
$badinput = false;
if(empty($name)){
echo "Please specify your name!";
exit(0);
}
else{
$name = "'" . $name . "'";
}
if($noInputMovieID && empty($ID)){
echo "Please specify movie ID!";
exit(0);
}
if(empty($rating)){
echo "Please specify rating!";
exit(0);
}
else if(!is_numeric($rating)){
echo "Rating must be a numeric number!";
exit(0);
}
else if($rating > 5){
echo "Rating cannot be more than 5";
exit(0);
}
if(empty($test)){
echo "Please give comments!";
exit(0);
}
else{
$comments = "'" . $comments . "'";
}
if(!$badinput){
$add = "insert into Review values(" . $name . ", " . $time . ", " . $ID . "," . $rating . "," . $comments . ");";
// echo $add;
mysql_query($add, $db_connection);
// $affected = mysql_affected_rows($db_connection);
// print "Total affected rows: $affected<br>";
if(mysql_errno($db_connection) == 0){
$noError = true;
}
else{
$noError = false;
}
if($noError){
echo "Comment successful!";
}
else{
echo "Comment error!";
}
}
}
?>
</h4>
</div>
</div>
</div>
<?php
mysql_close($db_connection);
page_foot();
?>