-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewprofile.php
91 lines (83 loc) · 3.12 KB
/
viewprofile.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
<?php
// Start the session
require_once('templates/startsession.php');
//Insert the page header
$page_title='View Profile';
require_once('templates/header.php');
require_once('appvars.php');
require_once('connectvars.php');
// Nav menu
require_once('templates/navmenu.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();
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Grab the profile data from the database
if (!isset($_GET['user_id'])) {
$query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '" . $_SESSION['user_id'] . "'";
}
else {
$query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_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>';
}
if (!empty($row['gender'])) {
echo '<tr><td class="label">Gender:</td><td>';
if ($row['gender'] == 'M') {
echo 'Male';
}
else if ($row['gender'] == 'F') {
echo 'Female';
}
else {
echo '?';
}
echo '</td></tr>';
}
if (!empty($row['birthdate'])) {
if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) {
// Show the user their own birthdate
echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>';
}
else {
// Show only the birth year for everyone else
list($year, $month, $day) = explode('-', $row['birthdate']);
echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>';
}
}
if (!empty($row['city']) || !empty($row['state'])) {
echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>';
}
if (!empty($row['picture'])) {
echo '<tr><td class="label">Picture:</td><td><img src="' . MM_UPLOADPATH . $row['picture'] .
'" alt="Profile Picture" /></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);
?>
<?php
// Insert the footer
require_once('templates/footer.php');
?>