-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete_funtion.php
41 lines (34 loc) · 1.14 KB
/
delete_funtion.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
<?php
// Process delete operation after confirmation
if(isset($_POST["id"])){
// Include config file
require_once "dist/php/connection.php";
// Prepare a delete statement
$sql = "DELETE FROM products WHERE product_id = ?";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_POST["id"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records deleted successfully. Redirect to landing page
header("location: landing_Adminpage.php");
exit();
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
// Close connection
mysqli_close($conn);
} else{
// Check existence of id parameter
if(empty(trim($_POST["id"]))){
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
}
?>