-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdelete.php
83 lines (63 loc) · 1.89 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
<?php
require_once "pdo.php";
session_start();
if (isset($_POST['cancel'])) {
header("Location: index.php");
return;
}
if (isset($_POST['profile_id']) ) {
$sql = "DELETE FROM profile WHERE profile_id = :pi";
$statement = $pdo->prepare($sql);
$statement->execute(array(
":pi" => $_POST['profile_id']
));
$_SESSION['success'] = "Profile deleted";
header("Location: index.php");
return;
}
if (!isset($_GET['profile_id'])) {
$_SESSION['error'] = "Could not load profile";
header("Location: index.php");
return;
}
$statement = $pdo->prepare("SELECT * FROM profile WHERE profile_id = :profile_id");
$statement->execute(array(
":profile_id" => $_GET["profile_id"],
));
$row = $statement->fetch(PDO::FETCH_ASSOC);
if ($row == false) {
$_SESSION['error'] = "Could not load profile";
header("Location: index.php");
return;
}
$first_name = htmlentities($row["first_name"]);
$last_name = htmlentities($row["last_name"]);
$email = htmlentities($row["email"]);
$headline = htmlentities($row["headline"]);
$summary = htmlentities($row["summary"]);
?>
<!DOCTYPE html>
<html>
<body>
<h1>Deleteing Profile </h1>
<?php
if (isset($_SESSION['error'])) {
echo "<p style='color: red'>".$_SESSION['error']."</p>";
unset($_SESSION['error']);
}
?>
<p>
First Name: <?php echo $first_name; ?>
</p>
<p>
Last Name: <?php echo $last_name; ?>
</p>
<form method="POST">
<p>
<input type="hidden" name="profile_id" value="<?= $_GET['profile_id'] ?>" />
</p>
<input type="submit" name="delete" value="Delete" />
<input type="submit" name="cancel" value="Cancel" />
</form>
</body>
</html>