-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcategory_handler.php
More file actions
49 lines (40 loc) · 1.73 KB
/
category_handler.php
File metadata and controls
49 lines (40 loc) · 1.73 KB
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
<?php
include('config.db.php');
include('dbplugin.php');
if (isset($_GET['delid'])) {
$delRec = addslashes($_GET['delid']);
$catdelquery = "UPDATE category SET status='DELETED' WHERE id='$delRec'";
mysqli_query($db, $catdelquery);
$errorMsg = "record deleted successfully";
header("Location: category.php?success=" . $errorMsg);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$category_name = addslashes($_POST['category']);
if ($category_name == "") {
$errorMsg = "Please enter category name";
header("Location: category.php?error=" . $errorMsg);
} else {
$check = "SELECT category,status FROM category WHERE category='$category_name'";
$result = mysqli_query($db, $check);
$row = mysqli_fetch_array($result);
$fcats = $row['category'];
$fcstatus = $row['status'];
$check_count = mysqli_num_rows($result);
if ($check_count > 0 && $fcstatus == 'ACTIVE') {
$errorMsg = "category already in the system";
header("Location: category.php?error=" . $errorMsg);
}
if ($check_count > 0 && $fcstatus == 'DELETED') {
$updatecat = "UPDATE category SET status='ACTIVE' WHERE category='$fcats'";
mysqli_query($db, $updatecat);
$successMsg = "category was added successfully.";
header("Location: category.php?success=" . $successMsg);
}
if ($check_count == 0) {
$insertCat = "INSERT INTO category (`id`, `category`, `status`) VALUES (NULL, '$category_name', 'ACTIVE')";
mysqli_query($db, $insertCat);
$successMsg = "category was added successfully.";
header("Location: category.php?success=" . $successMsg);
}
}
}