-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
163 lines (140 loc) · 5.03 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
<?php
// Process delete operation after confirmation using PDO
if(isset($_POST["id"]) && !empty($_POST["id"])){
// Include config file
require_once 'config.php';
// start transaction
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
// Prepare a delete statement
$sql = "DELETE FROM tasks WHERE id = :id";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(':id', $param_id);
// Set parameters
$param_id = trim($_POST["id"]);
// Attempt to execute the prepared statement
if($stmt->execute()){
// Records deleted successfully. Redirect to landing page
//header("location: carinfo.php");
//exit();
} else{
$pdo->rollBack();
echo "<p class='lead'><em>No records found for tasks.</em></p>";
exit();
}
}
// Prepare a delete statement
$sql = "DELETE FROM service WHERE id = :id";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(':id', $param_id);
// Set parameters
$param_id = trim($_POST["id"]);
// Attempt to execute the prepared statement
if($stmt->execute()){
// Records deleted successfully. Redirect to landing page
//header("location: carinfo.php");
//exit();
} else{
$pdo->rollBack();
echo "<p class='lead'><em>No records found for service.</em></p>";
exit();
}
}
// Prepare a delete statement
$sql = "DELETE FROM carinfo WHERE id = :id";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(':id', $param_id);
// Set parameters
$param_id = trim($_POST["id"]);
// Attempt to execute the prepared statement
if($stmt->execute()){
// Records deleted successfully. Redirect to landing page
//header("location: carinfo.php");
//exit();
} else{
$pdo->rollBack();
echo "<p class='lead'><em>No records found for carinfo.</em></p>";
exit();
}
}
// commit transactions
$pdo->commit();
echo "<p class='lead'><em>Successful transaction.</em></p>";
//sleep(10);
header("location: carinfo.php");
// Close statement
unset($stmt);
// Close connection
unset($pdo);
} else{
// Check existence of id parameter
if(empty(trim($_GET["id"]))){
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html">
<title>CarQuest</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(function() {
$('#header').load('menu.html');
});
</script>
<style type="text/css">
<!--
body,td,th {
color: LightGray;
}
body {
background-color: SlateGray;
}
a:link {
color: White;
}
-->
</style>
</head>
<body>
<div class="container">
<header>
<div id="header">
</div>
</header>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Delete Record</h1>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="alert alert-danger fade in">
<input type="hidden" name="id" value="<?php echo trim($_GET["id"]); ?>"/>
<p>Are you sure you want to delete THIS car and ALL related maintenance records?</p><br>
<p>
<input type="submit" value="Yes" class="btn btn-danger">
<a href="carinfo.php" class="btn btn-default">No</a>
</p>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>