-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.php
More file actions
109 lines (97 loc) · 3.06 KB
/
dashboard.php
File metadata and controls
109 lines (97 loc) · 3.06 KB
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
<?php
include 'db.php';
session_start();
if(isset($_SESSION['firstName']) && isset($_SESSION['lastName']) && isset($_SESSION['id'])){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$password = $_POST['password'];
$password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (firstName, lastName, username,
password) VALUES (?, ?, ?, ?)");
$stmt->execute([$firstName, $lastName, $username, $password]);
$success = "Data Inserted Successfully";
}
$stmt = $pdo->query("SELECT * FROM users");
$users = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container{
margin: 1rem;
padding: 1rem;
border: 1px solid #333;
border-radius: 10px;
}
.user{
float: right;
}
.alert p{
color: green;
}
</style>
</head>
<body>
<div class="container">
<p class="user">Hello: <?php if(isset($_SESSION['firstName']) && isset($_SESSION['lastName'])){
echo $_SESSION['firstName'] . " ".$_SESSION['lastName'];
} ?>
<a href="logout.php">Logout</a>
</p>
<br>
<div class="content">
<h3>Welcome to the Dashboard</h3>
</div>
<br>
<?php
if(isset($success)){
?>
<div class="alert">
<p><?php echo $success; ?></p>
</div>
<?php
}
?><br>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<label for="">First Name</label><br>
<input type="text" name="firstName" required><br>
<label for="">Last Name</label><br>
<input type="text" name="lastName" required><br>
<label for="">Username</label><br>
<input type="text" name="username" required><br>
<label for="">Password</label><br>
<input type="text" name="password" required><br><br>
<input type="submit">
</form>
<br>
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Status</th>
</thead>
<?php
foreach ($users as $user): ?>
<tbody>
<td><?php echo $user['firstName']; ?></td>
<td><?php echo $user['lastName']; ?> </td>
<td><?= $user['username'] ?> </td>
<td><?= ($user['status'] == 1) ? 'Active' : 'Not Active'; ?> </td>
</tbody>
<?php endforeach; ?>
</table>
</div>
</body>
</html>
<?php
}else{
header("location: index.php");
}
?>