-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadFile.php
137 lines (101 loc) · 3.56 KB
/
uploadFile.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<title>uMovies :: Movie</title>
<style type="text/css">
@import url(uMovies.css);
</style>
</head>
<body>
<div id="links">
<a href="./">Home<span> Access the database of movies, actors and directors. Free to all!</span></a>
<a href="admin.html">Administrator<span> Administrator access. Password required.</span></a>
</div>
<div id="content">
<h1>uMovies™</h1>
<p>
Welcome to <em>uMovies</em>, your destination for information on <a href="movies.php" title="access movies information">movies</a>, <a href="actors.php" title="access actors information">actors</a> and <a href="directors.php" title="access directors information">directors</a>.
</p>
<h2>Upload</h2>
<p>
<?php
set_time_limit(0);
$okay = true;
$db =new mysqli('localhost','uMoviesRoot','anonymous','uMovies');
if($db-> connect_error){
die("connection failed: ". $db -> connect_error);
}
echo "Connect successfully &";
$filename = 'uMovies.txt';
if($okay){
echo 'File uploaded successfully.';
$file = fopen($filename, 'r');
//maybe i can use a counter to to get the rest of the file.
while(!feof($file)){
$line = fgetcsv($file, 0,"\t");
if($line[0] == 'movie'){
$name = mysqli_real_escape_string($db,$line[1]);
$year = mysqli_real_escape_string($db,$line[2]);
$sql = "INSERT INTO `movies` (`name`, `year`) VALUES ('$name','$year')";
if($db -> query($sql) === TRUE){
}else{
echo "dude you suck";
}
}
if($line[0] == 'director'){
$name = mysqli_real_escape_string($db,$line[2]);
$year = mysqli_real_escape_string($db,$line[3]);
$director = mysqli_real_escape_string($db,$line[1]);
$sql = "INSERT INTO `directors` (`name`) VALUES ('$line[1]')";
$m = "INSERT INTO `directed_by` (`movie`, `year`, `director`) VALUES('$name' , '$year', '$director')";
if($db -> query($sql) === TRUE){
}else{
echo "Directors failed";
}
if($db -> query($m) === TRUE){
}else{
echo "Directed by";
}
}
if($line[0] == 'actress'){
$name = mysqli_real_escape_string($db,$line[1]);
$movie = mysqli_real_escape_string($db,$line[2]);
$year = mysqli_real_escape_string($db,$line[3]);
$role = mysqli_real_escape_string($db,$line[4]);
$sql = "INSERT INTO `actors`(`name`,`gender`) VALUES('$name', 'Female')";
$m = "INSERT INTO `performed_in`(`actor`, `movie`, `year`, `role`) VALUES ('$name', '$movie', '$year', '$role')";
if($db -> query($sql) === TRUE){
}else{
echo "woman";
}
if($db -> query($m) === TRUE){
}else{
echo "performed_in";
}
}
if($line[0] == 'actor'){
$name = mysqli_real_escape_string($db,$line[1]);
$movie = mysqli_real_escape_string($db,$line[2]);
$year = mysqli_real_escape_string($db,$line[3]);
$role = mysqli_real_escape_string($db,$line[4]);
$sql = "INSERT INTO `actors`(`name`,`gender`) VALUES('$name', 'Male')";
$m = "INSERT INTO `performed_in`(`actor`, `movie`, `year`, `role`) VALUES ('$name', '$movie', '$year', '$role')";
if($db -> query($sql) === TRUE){
}else{
echo "dude";
}
if($db -> query($m) === TRUE){
}else{
echo "maleperin";
}
}
$fields = count($line);
}
$db->close();
fclose($file);
}
?>
<p><a style = "text-decoration:none" href = "admin.html">
<input type = "submit" value=" Back to Upload"?></a></p>
</body></html>