-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathI1.php
171 lines (155 loc) · 4.82 KB
/
I1.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
<?php
$db_connection = mysql_connect("localhost", "cs143", "") or die('Could not connect'.mysql_error());
if (!db_connection) {
$errmsg=mysql_error($db_connection);
print "Connection failed <br>";
exit(1);
}
mysql_select_db("CS143", $db_connection);
function insertActor($last, $first, $sex, $dob, $dod)
{
$existQuery = "SELECT * FROM Actor WHERE last = '$last' AND first = '$first' AND sex = '$sex' AND dob = '$dob'";
$existResult = mysql_query($existQuery);
if ($existResult && mysql_fetch_row($existResult))
//Actor already exists in actor table.
{
print ("Actor already exists, no records updated.");
return;
}
$existQuery = "SELECT id FROM Director WHERE last = '$last' AND first = '$first' AND dob = '$dob'";
$existResult = mysql_query($existQuery);
//Actor already exists in director table.
$idNumber = mysql_fetch_row($existResult); //get id number of director
if ($idNumber[0]) //if able to fetch a row
{
$query = "INSERT INTO Actor VALUES ($idNumber[0], '$last', '$first', '$sex', '$dob', '$dod')";
$queryResults = mysql_query($query);
if ($queryResults)
{
print ("Existing director added to actor table.");
return;
}
}
else
{
$query = "UPDATE MaxPersonID SET id =id+1 WHERE id >= 0";
$queryResult = mysql_query($query);
$query = "SELECT id FROM MaxPersonID";
$queryResult = mysql_query($query);
$idNumber = mysql_fetch_row($queryResult);
$query = "INSERT INTO Actor VALUES ($idNumber[0], '$last', '$first', '$sex', '$dob', '$dod')";
$queryResult = mysql_query($query);
echo $query;
echo "<br>";
echo $idNumber[0];
if ($queryResult)
{
print ("New actor successfully added into Actor table");
}
else
{
print ("Oh no!");
}
}
}
function insertDirector($last, $first, $dob, $dod)
{
$existQuery = "SELECT * FROM Director WHERE last = '$last' AND first = '$first' AND dob = '$dob'";
$existResult = mysql_query($existQuery);
if ($existResult && mysql_fetch_row($existResult))
//Director already exists in Director table.
{
print ("Director already exists, no records updated.");
return;
}
$existQuery = "SELECT id FROM Actor WHERE last = '$last' AND first = '$first' AND dob = '$dob'";
$existResult = mysql_query($existQuery);
$idNumber = mysql_fetch_row($existResult);
if ($idNumber[0])
{
$query = "INSERT INTO Director VALUES ($idNumber[0], '$last', '$first', '$dob', '$dod')";
$queryResult = mysql_query($query);
if ($queryResult)
{
print ("Existing actor added to director table.");
return;
}
}
else
{
$query = "UPDATE MaxPersonID SET id = (id + 1)";
$queryResult = mysql_query($query);
$query = "SELECT id FROM MaxPersonID";
$queryResult = mysql_query($query);
$idNumber = mysql_fetch_row($queryResult);
$query = "INSERT INTO Director VALUES ($idNumber[0], '$last', '$first', '$dob', '$dod')";
$queryResult = mysql_query($query);
if ($queryResult)
{
print ("New director successfully added into Director table");
}
else
{
print ("Oh no!");
}
}
}
$identity = $_GET['identity'];
$last = $_GET['last'];
$first = $_GET['first'];
$sex = $_GET['sex'];
$dob = $_GET['dob'];
$dod = $_GET['dod'];
if ($identity && $first && $last && $sex && $dob)
{
if ($identity == 'actor')
insertActor($last, $first, $sex, $dob, $dod);
else
insertDirector($last, $first, $dob, $dod);
}
else
{
echo "No query was input";
}
echo <<<HTMLCODE
<html>
<title>Add Actor/Director</title>
<link rel="stylesheet" type="text/css" href="Project1C.css">
<div id="sidebar">
<ul>Add New Content:<br>
<li><a href="I1.php">Add Actor/Director</a></li>
<li><a href="I2.php">Add Movie Information</a></li>
<li><a href="I3.php">Add Comments</a></li>
<li><a href="I4.php">Add Movie/Actor Relation</a></li>
<li><a href="I5.php">Add Movie/Director Relation</a></li>
</ul>
<ul>Browsing Content:<br>
<li><a href="B1.php">Show Actor Information</a></li>
<li><a href="B2.php">Show Movie Information</a></li>
</ul>
<ul>Search Interface:<br>
<li><a href="S1.php">Search Actor/Movie</a></li>
</ul>
</div>
<div id="main">
Add New Actor/Director:<br>
<form method="GET" ACTION="I1.php">
Identity:
<input type="radio" value="actor" name="identity" checked="true">Actor
<input type="radio" value="director" name="identity" >Director<br>
<hr></hr>
First Name: <input type="text" maxlength="20" name="first"><br>
Last Name: <input type="text" maxlength="20" name="last"><br>
Sex:
<input type="radio" value="female" name="sex" checked="true">Female
<input type="radio" value="male" name="sex">Male<br>
Date of Birth: <input type="text" name="dob"><br/>
Date of Death: <input type ="text" name="dod"> (leave blank if still alive)<br/>
<hr></hr>
<input type="submit" value="Submit!">
</form>
</div>
</html>
HTMLCODE;
mysql_close($db_connection);
?>