-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
61 lines (51 loc) · 2.15 KB
/
user.php
File metadata and controls
61 lines (51 loc) · 2.15 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
<?php
require 'db.php';
$profile_id = isset($_GET['idu']) ? $_GET['idu'] : null;
$sql = "SELECT * FROM accounts WHERE id = '$profile_id'";
$result = $conn->query($sql);
$user = $result->fetch_assoc();
$posts_sql = "SELECT * FROM posts WHERE id = '$profile_id'";
$posts_result = $conn -> query($posts_sql);
$conn->close();
?>
<?php if($user): ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<base href="/form/">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700|Roboto+Slab:400,700" rel="stylesheet">
<link rel="stylesheet" href="user.css">
</head>
<body>
<?php require 'header.php';?>
<main>
<section class="profile">
<h1>User Profile</h1>
<div class="picture-container">
<img src="<?php echo htmlspecialchars($user['profile_pic'])?>" alt="User profile picture">
</div>
<h2><?php echo htmlspecialchars($user['username'])?></h2>
</section>
<section class="user-posts">
<h2>User Posts</h2>
<?php if ($posts_result->num_rows > 0): ?>
<?php while ($post = $posts_result->fetch_assoc()): ?>
<div class="post">
<h3><?php echo htmlspecialchars($post['title']); ?></h3>
<p><?php echo htmlspecialchars($post['content']); ?></p>
</div>
<?php endwhile; ?>
<?php else: ?>
<p>No posts found for this user.</p>
<?php endif; ?>
</section>
</main>
<?php include("footer.php"); ?>
</body>
</html>
<?php else:?>
<h1>User not found</h1>
<?php endif;?>