-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.php
executable file
·63 lines (59 loc) · 2.05 KB
/
permissions.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
<?php
$title = "Permission Page";
include('header.php');
include('config/db.php');
$permissionErr ="";
$permission = "";
$sql = "SELECT * FROM tbl_other";
$result = $conn->query($sql);
if (!empty($result)) {
while ($row = $result->fetch_assoc()) {
$roles[] = $row;
}
}
if (isset($_POST['submit'])) {
if (empty($_POST["permission"])) {
$permissionErr = "Permission is required.";
}
else {
$new_permission = $_POST["permission"];
$role = $_POST["role"];
$sql_permission = "SELECT permission FROM tbl_other WHERE id='".$role."'";
$result_permission_query = $conn->query($sql_permission);
$result_permission = $result_permission_query->fetch_assoc();
if (!empty($result_permission['permission'])) {
$permission = $result_permission['permission'].','.$new_permission;
$sql = "UPDATE tbl_other SET permission = '".$permission."' WHERE id='".$role."'";
} else {
$sql = "UPDATE tbl_other SET permission = '".$new_permission."' WHERE id='".$role."'";
}
if ($conn->query($sql) === TRUE) {
header("Location: permissions.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
}
?>
<div class="container">
<form method="post" action="permissions.php">
<div class="col-md-4 mar-all">
<div class="form-group">
<label for="permission">Permission</label>
<input type="text" class="form-control" name="permission" id="permission" placeholder="Enter Permission" value="<?php echo htmlspecialchars($permission);?>">
<span class="error"><?php echo $permissionErr;?></span>
</div>
<div class="form-group">
<label for="role">Role</label>
<select class="form-control" id="role" name="role">
<?php
foreach($roles as $key => $val) {
echo "<option value=".$val['id'].">".$val['role']."</option>";
} ?>
</select>
</div>
<button class="btn btn-lg btn-success" type="submit" name="submit">Submit</button>
</div>
</form>
</div>