-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_category.php
executable file
·89 lines (78 loc) · 2.73 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
<?php
session_start();
require_once 'classes/Util.php';
require_once 'classes/Category.php';
$util = new Util();
$util->validateAdmin();
$category = new Category();
$error_message = "";
$info = "";
if (isset($_POST['Edit'])) {
$response = $category->editCategory($_POST['id'],$_POST['name']);
if (!$response) {
if (isset($_SESSION['error_message'])) {
$error_message = $_SESSION['error_message'];
unset($_SESSION['error_message']);
}
} else {
$info = "Category edited successfully!";
}
}
$categoryDetails = array();
if (isset($_GET['category_id'])) {
$categoryId = $util->decryptPK($_GET['category_id']);
$categoryDetails = $category->getCategory($categoryId);
if (empty($categoryDetails)) {
$_SESSION['error_message'] = "The page you are looking for does not exist!";
header("Location:index.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Home - Recipes of the World</title>
<?php include_once('meta.php'); ?>
</head>
<body>
<?php include_once('header.php'); ?>
<section id="section1">
<?php include_once('_logout.php'); ?>
<div id="register-label">
Edit Category
</div>
</section>
<section id="section4">
<form method="post" action="">
<table align="center" width="30%" cellpadding="2" cellspacing="5" border="0">
<?php if(!empty($error_message)) {
?>
<tr>
<td colspan="2">
<div class="error"><?php echo $error_message; ?></div>
</td>
</tr>
<?php } ?>
<?php if(!empty($info)) {
?>
<tr>
<td colspan="2">
<div class="info"><?php echo $info; ?></div>
</td>
</tr>
<?php } ?>
<tr>
<td align="right">Name</td>
<td><input type="text" name="name" id="name" placeholder="Name" required value="<?php echo $categoryDetails['description']; ?>"></td>
</tr>
<tr align="center">
<td colspan="2"><button type="submit" name="Edit">Update</button></td>
</tr>
<tr>
<td colspan="2"><input type="hidden" name="id" value="<?php if (isset($categoryId)) { echo $categoryId; } ?>"></td>
</tr>
</table>
</form>
</section>
</body>
</html>