-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteProd.php
More file actions
37 lines (31 loc) · 961 Bytes
/
deleteProd.php
File metadata and controls
37 lines (31 loc) · 961 Bytes
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
<?php
session_start();
$_SESSION["username"] = "";
$isAdmin = $_SESSION["isAdmin"];
$id = $_COOKIE['id'];
if ($isAdmin == 0){
header("Refresh:0; url=index.php");
exit;
}
require "Query.php";
Query::connectDatabase();
$productID = $_POST['prodID'];
if(empty($_POST['prodID'])){
echo "<script>alert('Please enter the product ID you want to delete.');</script>";
}
else{
$query = "SELECT *
FROM PRODUCTS
WHERE pid = '$productID'";
$result = Query::$conn->query($query);
if(mysqli_num_rows($result) == 0){
echo "<script>alert('There is no product with the given product ID');</script>"; }
else{
$query = "DELETE FROM PRODUCTS WHERE pid = '$productID'";
if (Query::$conn->query($query) === TRUE) {
echo "<script>alert('Successfully deleted given product.');</script>";
}
}
}
header("Refresh:0; url=admin.php");
?>