-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.php
172 lines (140 loc) · 5.1 KB
/
delete.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
<?php
//orig idea overlay modal but cant be bothered;
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 = "Delete Anime";
$act1 = "active";
$act2=$act3=$act4 = "";
include "./includes/header.php";
// include the config file that we created before
require_once "./admin/config.php";
if (isset($_GET['id']) && !empty($_GET['id'])) {
// this is called a try/catch statement
try {
// FIRST: Connect to the database
$connection = new PDO($dsn, $username, $password, $options);
$animeid = $_GET['id'];
$userid = $_SESSION['id'];
// SECOND: Create the SQL
$sql1 ="SELECT * FROM anibase where anibase.animeid = :animeid group by :userid";
// THIRD: Prepare the SQL
$statement = $connection->prepare($sql1);
$statement->bindValue(':animeid', $animeid);
$statement->bindValue(':userid', $userid);
$statement->execute();
// FOURTH: Put it into a $result object that we can access in the page
$result = $statement->fetchAll();
if(isset($_POST['yes'])) {
try {
// define database connection
$connection = new PDO($dsn, $username, $password, $options);
// set id variable
$animeid = $_GET["id"];
// Create the SQL
$sql3 = "DELETE FROM anibase WHERE userid = :userid AND animeid = :animeid";
// Prepare the SQL
$statement3 = $connection->prepare($sql3);
// bind the id to the PDO
$statement3->bindValue(':animeid', $animeid);
$statement3->bindValue(':userid', $userid);
// execute the statement
$statement3->execute();
//this fetchAll gives a false error
$result3 = $statement3->fetchAll();
} catch(PDOException $error) {
// if there is an error, tell us what it is
// echo $sql3 . "<br>" . $error->getMessage();
}
}
foreach($result as $row) {
if(isset($_POST['cancel'])) {
header("Location: delete.php?id=".$row['animeid']."");
}
}
}
catch(PDOException $error) {
// if there is an error, tell us what it is
echo $sql1 . "<br>" . $error->getMessage();
}
if (isset($_POST['yes']) && $statement3) {?>
<h3 class='container-fluid bg-success'><p>Anime Successfully Deleted. </br>Results Refreshing...</p></h3>
<script> setTimeout(function() { window.location = "search.php"; }, 1250);</script>
<div class="container-fluid">
<h2>My Anime Index</h2>
<h3>Deleted <?php foreach($result as $row) { echo $row['animename'];}?>?</h3>
<?php
// header( "location: index.php");
}
?>
<?php foreach($result as $row) { ?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Anime</th>
<th>Episodes Watched</th>
<th>Are You Sure?</th>
</tr>
</thead>
<tbody>
<tr>
<td name="animename" value="<?php echo $row['animename'];?>"><?php echo $row['animename'];?></td>
<td name="episodes" value="<?php echo $row['episodes'];?>"><?php echo $row['episodes'];?></td>
<td><a data-toggle="modal" data-target="#myModal" data-id="<?php echo $row['animeid'];?>" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-trash"></span>
</a></td>
</tr>
</tbody>
</table>
<?php } ?>
<!-- Modal START -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Are You Sure?</h4>
</div>
<?php foreach($result as $row) {?>
<form method="post" action="delete.php?id=<?php echo $row['animeid'];?>" class="container">
<div class="modal-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Anime</th>
<th>Episodes Watched</th>
</tr>
</thead>
<tbody>
<tr>
<td name="animename" value="<?php echo $row2['animename'];?>"><?php echo $row['animename'];?></td>
<td name="episodes" value="<?php echo $row['episodes'];?>"><?php echo $row['episodes'];?></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<input type="submit" name="yes" value="YES" class="btn-update btn-danger btn btn-default btn-sm">
<input type="submit" name="cancel" value="CANCEL" class="btn-update btn-success btn btn-default btn-sm">
</div>
</form>
<?php }?>
</div>
</div>
</div>
<!-- Modal END -->
</div>
</body>
</html>
<?php
}else{
echo "Error: Unknown ID";
}
?>