-
Notifications
You must be signed in to change notification settings - Fork 1
/
category_add.php
145 lines (124 loc) · 4.38 KB
/
category_add.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/************************************
* File Name: category_add.php *
* Author: Ammar S.A.A *
* Output: Form to add new category *
************************************/
require('config.php');
require(WEBSITE_PATH.'./includes/db_connection.php');
require(WEBSITE_PATH.'./includes/session.php');
include(WEBSITE_PATH.'./includes/header.php');
include(WEBSITE_PATH.'./includes/logo.php');
include(WEBSITE_PATH.'./includes/menu.php');
// perform user signup
if (isset($_POST['category']))
{
$category_name = trim($_POST['category-name']);
$status = ($_POST['status']);
if (!empty($category_name) && !empty($status)){
//Update Query
if (isset($_GET['id'])){
$sql = "UPDATE `tblcategory` SET
`category_name` = '{$category_name}',
`status` = '{$status}'
WHERE id={$_POST['id']}";
$result = $conn->query($sql);
if ($result)
{
$msg = "<div class='alert alert-success'>Updation Successful To View Category Click/Tap <a href='".WEBSITE_URL."/category_list.php'>HERE</a>😀.</div>";
}else{
$msg = "<div class='alert alert-danger'>Errors Occured!</div>";
}
}
else{
if (IfExist(TBLCATEGORIES, 'category_name', $category_name)) {
$msg = "<div class='alert alert-info'>Duplicate Entry for <strong>".$category_name."</strong> To View Category List Click/Tap <a href='".WEBSITE_URL."/category_list.php'>HERE</a>.</div>";
}else{
//Insert Query
$sql = "INSERT INTO `tblcategory`
(`category_name`, `status`)
VALUES
('{$category_name}','{$status}')";
$result = $conn->query($sql);
if ($result)
{
$msg = "<div class='alert alert-success'>Entry Successful To View Category Click/Tap <a href='".WEBSITE_URL."/category_list.php'>HERE</a>😀.</div>";
}else{
$msg = "<div class='alert alert-danger'>Errors Occured!</div>";
}
}
}
}else{
$msg = "<div class='alert alert-danger'>Category Or Status Cannot Be Empty.</div>";
}
}
$category_name = '';
$status = '';
if (isset($_GET['id'])){
$select = "SELECT * FROM `tblcategory` WHERE id={$_GET['id']}";
$result = $conn->query($select);
if ($result && $result->num_rows > 0){
$row = $result->fetch_assoc();
$id = $row['id'];
$category_name = $row['category_name'];
$status = $row['status'];
};
}
if (isset($msg))
{
echo $msg;
}
?>
<section id="content">
<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col">
<h2>Add Category <hr/></h2>
</div>
</div>
<div class="col">
<!--Category Adding Form-->
<form class="form" name="category" method="post" action="#">
<br />
<input type="hidden" name="category" value="category" />
<input type="hidden" name="id" value="<?php echo $id;?>" />
<span class="f-img fa fa-file-zip-o fa-5x"></span>
<h5>Category Info</h5>
<p class="labelenglish"><b>Category Name:</b></p>
<input type="text" name="category-name" class="blank form-control-lg" value="<?php echo $category_name ?>" />
<p class="labelenglish"><b>Status:</b></p><br />
<div class="form-check form-check-inline" name="status">
<input class="form-check-input" type="radio" name="status" value="Active" <?php if ($status === 'Active') { echo "Checked"; } elseif ($status === 'Inactive') { echo " "; } else { echo " ";}?> />
<label class="form-check-label" for="status">
Active
</label>
</div>
<div class="form-check form-check-inline" name="status">
<input class="form-check-input" type="radio" name="status" value="Inactive" <?php if ($status === 'Inactive') { echo "Checked"; } elseif ($status === 'Active') { echo " "; } else { echo " ";}?> />
<label class="form-check-label" for="status">
Inactive
</label>
</div>
<div>
<input type="reset" name="reset" value="Reset" class="btn btn-success" />
<?php
if (isset($_GET['id'])) {
echo "<input type='submit' name='submit' value='Update' class='btn btn-success' />";
}
else{
echo "<input type='submit' name='submit' value='Add' class='btn btn-success' />";
}
?>
</div>
<br />
</form>
</div>
</div>
</div>
</section>
</div>
</div>
<?php
include(WEBSITE_PATH.'./includes/footer.php');
?>