-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.php
194 lines (160 loc) · 4.36 KB
/
categories.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=|, initial-scale=1.0">
<title>Categories</title>
</head>
<body>
<?php include('header_.php')?>
<?php include('config.php')?>
<?php
error_reporting(0);
$catid = $_GET['catid'];
$sql = "SELECT * FROM `category` where catid = '$catid'";
$rs = mysqli_query($con,$sql);
$catdata = mysqli_fetch_array($rs);
if($_GET['delid']){
$delid = $_GET['delid'];
$sql1 = "DELETE FROM `category` WHERE catid = '$delid'";
mysqli_query($con,$sql1);
header('Location: categories.php');
}
?>
<div class="form-containers">
<form action="" method="post">
<h3>add category</h3>
<input type="hidden" name="cid" value="<?= $catdata['catid']?>">
<input type="text" name="Name" required value="<?= $catdata['name']?>" placeholder="Enter the type of categories">
<input type="submit" name="addcat" value="Add Category" class="form-btn">
<input type="submit" name="updatecat" value="Update Category" class="form-btn">
</form>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Action</th>
</tr>
<?php
$sql = "SELECT * FROM `category`";
$rs = mysqli_query($con,$sql);
while($data = mysqli_fetch_array($rs)){
?>
<tr>
<td><?= $data['catid'] ?></td>
<td><?= $data['name'] ?></td>
<td>
<a href="categories.php?catid=<?= $data['catid'] ?>" class="btn btn-primary">Edit</a>
<a href="categories.php?delid=<?= $data['catid'] ?>" class="btn btn-danger">Delete</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
margin-left: 100px;
}
td, th{
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
text-align: center;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.form-containers{
min-height: 90vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
padding-bottom: 60px;
background: #eee;
}
.form-containers form{
padding: 20px;
border-radius: 5px;
box-shadow: 0 5px 10px rgba(0,0,0,.1);
background: #aec6cf;
text-align: center;
width: 500px;
}
.form-containers form h3{
font-size: 30px;
text-transform: uppercase;
margin-bottom: 10px;
color: #333;
}
.form-containers form textarea,
.form-containers form input,
.form-containers form select{
width: 100%;
padding: 10px 15px;
font-size: 17px;
background: #d3d3d3;
margin: 8px 0;
border-radius: 5px;
}
.form-containers form select option{
background: #fff;
}
.form-containers form .form-btn{
background: #fbd0d9;
color: crimson;
text-transform: capitalize;
font-size: 20px;
cursor: pointer;
}
.form-containers form .form-btn:hover{
background: crimson;
color: #fff;
}
.form-containers form p{
margin-top: 10px;
font-size: 20px;
color: #333;
}
.form-containers form p a{
color: crimson;
}
.form-containers form .error-msg{
margin: 10px 0;
display: block;
background: crimson;
color: #fff;
border-radius: 5px;
font-size: 20px;
padding: 10px;
padding: 10px;
}
</style>
</body>
</html>
<?php
if(isset($_POST['addcat'])){
$catname = $_POST['Name'];
if(mysqli_query($con,"INSERT INTO `category`(`name`) VALUES ('$catname')")){
echo "<script> alert('record inserted')";
}else{
echo "<script> alert('record not inserted')";
}
}
//update
if(isset($_POST['updatecat'])){
$cid = $_POST['cid'];
$catname = $_POST['Name'];
if(mysqli_query($con,"UPDATE `category` SET `name`='$catname' WHERE catid = '$cid'")){
echo "<script> alert('record inserted')";
}else{
echo "<script> alert('record not inserted')";
}
}
?>