You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Code2C/homepage.php

166 lines
4.8 KiB

6 months ago
<?php
// Start the session and check if the user is logged in
session_start();
// Check if the user is logged in
if (!isset($_SESSION["loggedInUser"])) {
header("Location: login.php"); // Redirect to login page if not logged in
exit();
}
// Database connection
$conn = new mysqli('localhost', 'root', '', 'user'); // Replace with your database credentials
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the logged-in user's email from the session
$email = $_SESSION["loggedInUser"];
// Create SQL query using prepared statements
$sql = "SELECT username, email, streak FROM registration WHERE email = ?";
$stmt = $conn->prepare($sql);
// Check if the statement was prepared successfully
if (!$stmt) {
die("SQL Error: " . $conn->error);
}
// Bind the parameter
$stmt->bind_param("s", $email);
// Execute the query
$stmt->execute();
// Get the result of the query
$result = $stmt->get_result();
// Check if the user exists
if ($result->num_rows > 0) {
// Fetch the user's data
$user = $result->fetch_assoc();
$userName = $user['username'];
$userEmail = $user['email'];
$userStreak = $user['streak'];
} else {
// If no user found, set default values
$userName = "Guest";
$userEmail = "Not Found";
$userStreak = 0;
}
// Close the statement and connection
$stmt->close();
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Welcome to our homepage. Explore our services, products, and more.">
<title>User Profile</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #007bff;
color: white;
padding: 1rem 2rem;
text-align: center;
}
nav {
display: flex;
justify-content: center;
background-color: #333;
}
nav a {
color: white;
text-decoration: none;
padding: 1rem;
margin: 0 0.5rem;
}
nav a:hover {
background-color: #575757;
border-radius: 5px;
}
main {
padding: 2rem;
}
footer {
background-color: #007bff;
color: white;
text-align: center;
padding: 1rem;
position: fixed;
bottom: 0;
width: 100%;
}
.profile-card {
width: 50%;
margin: 30px auto;
padding: 20px;
background-color: #f4f4f9;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.profile-card h2 {
text-align: center;
}
.profile-card p {
font-size: 18px;
color: #333;
}
.profile-card strong {
color: #007bff;
}
</style>
</head>
<body>
<header>
<h1>Welcome to Info Path</h1>
<p>Your one-stop destination for quality content and services.</p>
</header>
<nav>
<a href="homepage.php">Home</a>
<a href="about.html">About</a>
<a href="services.html">Services</a>
<a href="contact.html">Contact</a>
<a href="login.php">Log Out</a>
</nav>
<main>
<!-- Education Photo and App Description Section -->
<section class="content-section">
<div>
<h3 ></h3>
<br>
<p>Info Path is a student-oriented app designed to provide personalized educational content, resources, and tools to enhance learning and academic success. Our platform is tailored to meet the unique needs of each student, making education more accessible and engaging. With features such as interactive learning modules, real-time progress tracking, and collaborative study spaces, Info Path empowers students to take control of their learning journey. Additionally, the app offers guidance and support from experienced educators, ensuring students receive the help they need to succeed. Whether you're looking for supplementary study materials or a comprehensive learning solution, Info Path is here to support your academic goals every step of the way.</p>
</div>
6 months ago
</section>
<!-- User Profile Section -->
<section id="profile">
<div class="profile-card">
<h2>User Profile</h2>
<p><strong>Name:</strong> <?php echo htmlspecialchars($userName); ?></p>
<p><strong>Email:</strong> <?php echo htmlspecialchars($userEmail); ?></p>
<p><strong>Streak:</strong> <?php echo htmlspecialchars($userStreak); ?></p>
</div>
</section>
</main>
<footer>
<p>&copy; 2025 Your Website Name. All Rights Reserved.</p>
</footer>
</body>
</html>