-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_category.php
More file actions
33 lines (27 loc) · 993 Bytes
/
delete_category.php
File metadata and controls
33 lines (27 loc) · 993 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
<?php
$servername = "localhost";
$db_username = "your_db_username";
$db_password = "your_db_password";
$dbname = "mbzstore";
$conn = mysqli_connect('localhost', 'root', '', 'mbzstore');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
};
include 'common_functions.php';
session_start();
?>
<?php
// delete_category.php
if(isset($_GET['category_id'])){
// Sanitize the input to prevent SQL injection
$category_id = mysqli_real_escape_string($conn, $_GET['category_id']);
$delete_category_query = "DELETE FROM `categories` WHERE category_id = $category_id";
$result_category = mysqli_query($conn, $delete_category_query);
if($result_category){
echo "<script>alert('Category deleted successfully!')</script>";
echo "<script>window.location.href='view_categories.php'</script>"; // Redirect to the category list or any other page
} else {
echo "<script>alert('Error deleting category')</script>";
}
}
?>