-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewprofile.php
More file actions
70 lines (59 loc) · 2.1 KB
/
viewprofile.php
File metadata and controls
70 lines (59 loc) · 2.1 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
<?php
require_once('inc/startsession.php');
/////////////////////////////////////////////////////////////////////
//
// Written by Jim Garbe-- Dynamic Checksheet
//
/////////////////////////////////////////////////////////////////////
$Title="View Profile";
require_once('inc/title.php');
require_once('inc/appvars.php');
require_once('inc/connectvars.php');
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id']) ) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
else
{
echo ' <a href="editprofile.php">Edit Profile</a><br />';
echo ' <a href="logout.php">Log Out (' . $_SESSION['username'] . ')</a><br />';
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
?>
</div>
<?php
// Grab the profile data from the database
if (!isset($_GET['user_id'])) {
$query = "SELECT username, first_name, last_name FROM _user WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
else {
$query = "SELECT username, first_name, last_name FROM _user WHERE user_id = '" . $_GET['user_id'] . "'";
}
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 1) {
// The user row was found so display the user data
$row = mysqli_fetch_array($data);
echo '<table>';
if (!empty($row['username'])) {
echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';
}
if (!empty($row['first_name'])) {
echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></tr>';
}
if (!empty($row['last_name'])) {
echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>';
}
echo '</table>';
if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>';
}
} // End of check for a single row of user results
else {
echo '<p class="error">There was a problem accessing your profile.</p>';
}
mysqli_close($dbc);
?>
</body>
</html>