-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
161 lines (138 loc) · 5.08 KB
/
index.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
<?php
//changed index from search to view my list
// has a prob with displaying all from database including other users
//in future combine search and view list or combine myanimelist api
// too fixated on this crud web app i could have just submit the basics of what the assignment required
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
}
else{
header("location: login.php");
exit;
}
// Include config file
$title = "My AniDEX";
$act1 = "active";
$act2=$act3=$act4 = "";
include "./includes/header.php";
// include the config file that we created before
require_once "./admin/config.php";
// this is called a try/catch statement
try {
// FIRST: Connect to the database
$connection = new PDO($dsn, $username, $password, $options);
$userid = $_SESSION['id'];
// SECOND: Create the SQL
$sql = "SELECT * FROM anibase, users where anibase.userid = users.id and users.id= :id order by animename";
// THIRD: Prepare the SQL
$statement = $connection->prepare($sql);
$statement->bindValue(':id', $userid);
$statement->execute();
// FOURTH: Put it into a $result object that we can access in the page
$result = $statement->fetchAll();
} catch(PDOException $error) {
// if there is an error, tell us what it is
echo $sql . "<br>" . $error->getMessage();
}
try {
// FIRST: Connect to the database
$connection = new PDO($dsn, $username, $password, $options);
$userid = $_SESSION['id'];
// SECOND: Create the SQL
$sql = "SELECT * FROM users where id = :id";
// THIRD: Prepare the SQL
$statement = $connection->prepare($sql);
$statement->bindValue(':id', $userid);
$statement->execute();
// FOURTH: Put it into a $result object that we can access in the page
$result1 = $statement->fetchAll();
} catch(PDOException $error) {
// if there is an error, tell us what it is
echo $sql . "<br>" . $error->getMessage();
}
?>
<div class="container-fluid">
<?php foreach ($result1 as $row) {?>
<h2 class="text-center">Welcome to AniDEX: <?php echo $row['username'];?></h2>
<?php
}
if (!empty($result)){
?>
<h2>Search My AniDEX</h2>
<div class="search_query">
<input type="text" id="search_query" placeholder="Search for an Anime.." name="search">
<button type="submit" name="submit">
<i class="fa fa-search">
</i>
</button>
</div>
<table class="table">
<thead>
<tr>
<th>Anime</th>
<th>Episodes Watched</th>
<th>Edit</th>
<th>Remove From My List</th>
</tr>
</thead>
<tbody class="search_table">
<?php foreach($result as $row) {?>
<tr>
<td> <div class="row">
<div class="col-sm-6 center-block col-md-6 col-lg-6 col-sm-push-3">
<?php
echo "<b>". $row['animename'] . "</b>";
?>
</div>
<div class="col-sm-6 col-sm-offset-6 col-md-offset-7 col-lg-offset-7 col-md-4 col-lg-4 col-sm-pull-3">
<?php
switch(TRUE)
{
case (!empty($row['image']) && $row['imageup'] == 0):
echo "<img class='img-fluid img-thumbnail thumbnail' src='" . $row["image"] . "' alt='" . $row['animename'] . "'>";
break;
case (!empty($row["imageup"]) && $row['image'] == 0):
echo "<img class='img-fluid img-thumbnail thumbnail' src='" . $row["imageup"] . "' alt='" . $row['animename'] . "'>";
break;
case (empty($row['image']) || $row['image'] == 0):
echo "<p class='small'>No image available.</p>";
break;
case (empty($row['imageup']) || $row['imageup'] == 0):
echo "<p class='small'>No image available.</p>";
break;
default: echo "<p class='small'>No image available.</p>";
}
?>
</div>
</div></td>
<td><?php echo $row['episodes'];?></td>
<td>
<a href="edit.php?id=<?php echo $row['animeid'];?>" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-edit"></span>
</a>
</td>
<td>
<a href="delete.php?id=<?php echo $row['animeid'];?>" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-remove"></span>
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } else{
?>
<div class="container">
<a href="add.php">
<button class="btn btn-primary btn-start btn-sm">Click here to add your first Anime!</button>
</a>
<a href="search.php">
<button class="btn btn-primary btn-start btn-sm">Click here to search your first Anime!</button>
</div>
</a>
<?php
}?>
</body>
</html>