-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinsert_category.php
116 lines (102 loc) · 3.2 KB
/
insert_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
114
115
116
<?php
include 'auth/database.php';
$message = "";
if(!empty($_POST))
{
$output = "";
$category_name = mysqli_real_escape_string($connect, $_POST['category_name']);
$status = $_POST['status'];
$query = "INSERT INTO category(category_name, status) VALUES('$category_name', '$status')";
$message = "Data Inserted Successfully!!!";
if(mysqli_query($connect, $query))
{
//$output .= "<p class='bg-success text-white w-100 pt-2 pb-2 pl-3 pr-3 mb-3' style='border-radius: 5px;'>Store Added Successfully...</p>";
$output .= "
<div class='alert alert-success alert-dismissible fade show w-100' role='alert'>
<strong>" . $message . "</strong>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>
";
$select_query = "SELECT * FROM category ORDER BY id DESC";
$result = mysqli_query($connect, $select_query);
$output .= "
<table class='table table-striped' id='category_table'>
<thead class='thead-dark'>
<tr>
<th scope='col'>Id</th>
<th scope='col'>Category Name</th>
<th scope='col'>Status</th>
<th scope='col'>Action</th>
</tr>
</thead>
";
while($data = mysqli_fetch_array($result))
{
if($data['status'] == 'active')
{
$output .= "
<tbody
<tr>
<td> " . $data['id'] . "</td>
<td> " . $data['category_name'] . "</td>
<td><span class='active-status'>" . $data['status'] . "</span></td>
<td>
<div class='row'>
<button type='submit' name='edit' id='" . $data['id'] . "' class='btn btn-sm btn-primary mr-2 edit_data'>Edit</button>
<a href='delete_category.php?id=" . $data['id'] . "' name='cancel' class='btn btn-sm btn-danger delete_data'>Delete</a>
</div>
</td>
</tr>
</tbody>
";
}
else
{
$output .= "
<tbody
<tr>
<td> " . $data['id'] . "</td>
<td> " . $data['category_name'] . "</td>
<td><span class='inactive-status'>" . $data['status'] . "</span></td>
<td>
<div class='row'>
<button type='submit' name='edit' id='" . $data['id'] . "' class='btn btn-sm btn-primary mr-2 edit_data'>Edit</button>
<a href='delete_category.php?id=" . $data['id'] . "' name='cancel' class='btn btn-sm btn-danger delete_data'>Delete</a>
</div>
</td>
</tr>
</tbody>
";
}
}
$output .= "</table>";
}
echo $output;
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.active-status{
background-color: #28a745 !important;
font-size: 14px;
color: white;
padding: 1.5px 5px;
border-radius: 2px;
}
.inactive-status{
background-color: #dc3545 !important;
font-size: 14px;
color: white;
padding: 1.5px 5px;
border-radius: 2px;
}
</style>
</head>
<body>
</body>
</html>