-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.php
110 lines (101 loc) · 3.69 KB
/
users.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
<?php require 'config.php' ?>
<?php
include 'connection.php';
$query = "SELECT * FROM welcome";
$statement = $connect->prepare($query);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_OBJ); //PDO::FETCH_ASSOC
$result = $statement->fetchAll();
if($result)
{
foreach($result as $row);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jee</title>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<script type="text/javascript" src="./bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<?php if(isset($_GET['error'])) {
require 'error.php';
} ?>
<body>
<?php include 'partials/header.php' ?>
<?php if (!isset($_SESSION["role"])) {
header('location: login.php'); }
else if($_SESSION['role'] != 'admin'){
header('location: index.php');} ?>
<div class="card ">
<div class="card-header">
<h3><i class="fas fa-users mr-2"></i>User list <span class="float-right">Welcome! <strong>
</strong></span></h3>
</div>
<div class="card-body pr-2 pl-2">
<form action="add_user.php" method="post">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">Username</span>
</div>
<input type="text" class="form-control" placeholder="..." name="username" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-default">Password</span>
</div>
<input type="password" class="form-control" placeholder="..." name="password" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<select class="form-control" name="role" id="role">
<option value="" disabled selected>Valitse rooli</option>
<option value="admin" name="admin">admin</option>
<option value="user" name="user">user</option>
</select>
<input type="submit" id="usersubmit" name="Addusersubmit" class="btn btn-primary btn-lg" value="Submit"/>
</form>
<br>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<?php
include 'connection.php';
$query = "SELECT * FROM user";
$statement = $connect->prepare($query);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_OBJ); //PDO::FETCH_ASSOC
$result = $statement->fetchAll();
if($result)
{
foreach($result as $row)
{
?>
<tr>
<td><?= $row->id; ?></td>
<td><?= $row->username; ?></td>
<td><?= $row->role; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="5">No Record Found</td>
</tr>
<?php
}
?>
<thead>
<tr>
<th class="text-center">Id</th>
<th class="text-center">Username</th>
<th class="text-center">Role</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>