-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_category.php
113 lines (100 loc) · 4.03 KB
/
edit_category.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
<?php
session_start();
require 'db.php';
if(!isset($_SESSION['user_id'])){
header('Location: login.php');
exit();
}else{
$user_id = $conn->real_escape_string($_SESSION['user_id']);
$sql= "SELECT * FROM users WHERE ID = $user_id";
$result = $conn->query($sql);
if($result->num_rows>0){
$user_check=$result->fetch_assoc();
if($user_check['Type']!=1){
header('Location: profile.php');
exit();
}
}
}
if(!isset($_GET['id'])){
header('Location: category.php');
exit();
}else{
$category_id=$conn->real_escape_string($_GET['id']);
$sql="SELECT Name,user_id FROM categories WHERE ID=$category_id";
$result = $conn->query($sql);
if($result && $result->num_rows == 1){
$category_data=$result->fetch_assoc();
}else{
die('Something went wrong in the database fetching in single category data.');
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['categoryname'])) {
$categoryname = $conn->real_escape_string($_POST['categoryname']);
$update_sql = "UPDATE categories SET Name = '$categoryname' WHERE ID = $category_id";
if ($conn->query($update_sql) === true) {
header('Location: category.php');
exit();
} else {
$_SESSION['error'] = 'Error updating brand.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Category</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light p-4 w-100">
<a class="navbar-brand" href="admin.php">Admin</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="profile.php">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="brand.php">Brand</a>
</li>
<li class="nav-item">
<a class="nav-link" href="category.php">Category</a>
</li>
<li class="nav-item">
<a class="nav-link" href="products.php">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<h2>Update Category</h2>
<?php if (isset($_SESSION['error'])): ?>
<div class="alert alert-danger">
<?php echo $_SESSION['error']; unset($_SESSION['error']); ?>
</div>
<?php endif; ?>
<form action="" method="post">
<div class="mb-3">
<label for="categoryname" class="form-label">Category Name</label>
<input type="text" class="form-control" name="categoryname"
value="<?php echo $category_data['Name']; ?>" required>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>