-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelation.php
179 lines (177 loc) · 5.22 KB
/
relation.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
<?php
require_once('facilities.php');
page_head('Add Relation');
$db_connection = getConnection();
?>
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Add Relationships</h2>
</div>
</div>
<div class="container">
<div class="col-md-12">
<div class="row">
<div class="col-md-1">
<div class="row">
<h4><input type = "radio" name = "Ctype" value = "actor" checked>Actor</h4>
</div>
</div>
<div class="col-md-11">
<div class="row">
<div class="col-md-2">
<h4>Actor ID<sup>*</sup>:</h4>
</div>
<div class="col-md-6">
<textarea name = "Actor_id"></textarea>
</div>
</div>
<div class="row">
<div class="col-md-2">
<h4>Role in the movie<sup>*</sup>:</h4>
</div>
<div class="col-md-6">
<textarea name = "Actor_role"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<!--radio box for director-->
<div class="container">
<div class="col-md-12">
<div class="row">
<div class="col-md-1">
<div class="row">
<h4><input type = "radio" name = "Ctype" value = "director">Director</h4>
</div>
</div>
<div class="col-md-11">
<div class="row">
<div class="col-md-2">
<h4>Director ID<sup>*</sup>:</h4>
</div>
<div class="col-md-6">
<textarea name = "Director_id"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<h4>Movie ID<sup>*</sup>:</h4>
</div>
<div class="col-md-6">
<textarea name = "Movie_id"></textarea>
</div>
</div>
<div class="row">
<input type = "submit" name = "submit_relation" value = "Submit Actor/Director and Movie Relations">
</div>
</form>
<div class="row">
<h4>
<?php
if($_POST['submit_relation']){
$ctype = $_POST['Ctype'];
$movie_id = $_POST['Movie_id'];
$badinput = false;
$isActor = true;
$msg = "";
if($ctype == "actor"){
$actorid = $_POST['Actor_id'];
$actorid = trim($actorid);
$actorrole = $_POST['Actor_role'];
$isActor = true;
if(empty($actorid)){
echo "Please specify the actor's ID!<br>";
exit(0);
}
else{// if no such actor exist
$select = "select * from Actor where id = " . $actorid . ";";
mysql_query($select, $db_connection);
$affect = mysql_affected_rows($db_connection);
if($affect == 0){
$msg .= "No actor with ID: " . $actorid . " is found<br>";
echo $msg;
exit(0);
}
}
if(empty($actorrole)){
echo "Please specify the actor's role in the movie!<br>";
exit(0);
}
else{
$actorrole = "'" . $actorrole . "'";
}
}
if($ctype == "director" ){
$directorid = $_POST['Director_id'];
$directorid = trim($directorid);
$isActor = false;
if(empty($directorid)){
echo "Please specify the director's ID!<br>";
exit(0);
}
else{// if no such director exist
$select = "select * from director where id = " . $directorid . ";";
mysql_query($select, $db_connection);
$affect = mysql_affected_rows($db_connection);
if($affect == 0){
$msg .= "No director with ID: " . $directorid . " is found<br>";
echo $msg;
exit(0);
}
}
}
if(empty($movie_id)){
echo "Please specify the movie's ID!<br>";
exit(0);
}
else{
$select = "select * from Movie where id = " . $movie_id . ";";
mysql_query($select, $db_connection);
$affect = mysql_affected_rows($db_connection);
if($affect == 0){
$msg .= "No movie with ID: " . $movieID . " is found<br>";
echo $msg;
exit(0);
}
}
if(!$badinput){
$add = "insert into ";
if($isActor){
$add = $add . "MovieActor" . " values(" . $movie_id . ", " . $actorid . ", " . $actorrole . ");";
}
else{
$add = $add . "MovieDirector" . " values(" . $movie_id . ", " . $directorid . ");";
}
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 "Relation construction successful!<br>";
}
else{
echo "Relation already existed<br>";
}
}
}
?>
</h4>
</div>
</div>
<?php
mysql_close($db_connection);
page_foot();
?>