-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletesubscriber-single.php
118 lines (97 loc) · 2.76 KB
/
deletesubscriber-single.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
<?php
include('functions.php');
if (!isLevel1()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['user']);
header("location: login.php");
}
?>
<?php
/**
* Delete a user
*/
require "config.php";
require "common.php";
if (isset($_GET["id"])) {
try {
$connection = new PDO($dsn, $username, $password, $options);
$id = $_GET["id"];
$sql = "DELETE FROM subscribers WHERE id = :id";
$statement = $connection->prepare($sql);
$statement->bindValue(':id', $id);
$statement->execute();
$success = "Subscriber successfully deleted";
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
if (isset($_POST['submit'])) {
try{
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM subscribers
WHERE firstname = :firstname
AND lastname = :lastname";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$statement = $connection->prepare($sql);
$statement->bindParam(':firstname', $firstname, PDO::PARAM_STR);
$statement->bindParam(':lastname', $lastname, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<?php require "templates/header.php"; ?>
<h2>Delete</h2>
<?php
if (isset($_POST['submit'])) {
if ($result && $statement->rowCount() > 0) { ?>
<h2>Results</h2>
<table>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Card Number</th>
<th>CVV</th>
<th>Location</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) { ?>
<tr>
<td><?php echo escape($row["id"]); ?></td>
<td><?php echo escape($row["firstname"]); ?></td>
<td><?php echo escape($row["lastname"]); ?></td>
<td><?php echo escape($row["cardnumber"]); ?></td>
<td><?php echo escape($row["cvv"]); ?></td>
<td><?php echo escape($row["location"]); ?></td>
<td><?php echo escape($row["date"]); ?> </td>
<td><a href="deleteSubscriber2.php?id=<?php echo escape($row["id"]); ?>">Delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } else { ?>
> No results found for <?php echo escape($_POST['lastname']); ?>.
<?php }
} ?>
<h2>Please Confirm the following Information</h2>
<form method="post">
<label for="location">First Name</label>
<input type="text" id="firstname" name="firstname">
<label for="location">Last Name</label>
<input type="text" id="lastname" name="lastname">
<input type="submit" name="submit" value="View Results">
</form>
<a href="userLogin.php">Back to home</a>
<?php require "templates/footer.php"; ?>