connect_error) { die("Connection failed: " . $conn->connect_error); } $email = trim($_SESSION["loggedInUser"]); // Fetch the user details from the registration table $sql = "SELECT * FROM registration WHERE email = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("s", $email); $stmt->execute(); $result = $stmt->get_result(); // Get user details if ($result->num_rows > 0) { $user = $result->fetch_assoc(); $user_id = $user['id']; } else { echo "No user found."; exit(); } // Get the streak $streak = 0; $today = date('Y-m-d'); $last_login = null; // Get the login dates of the user $sql = "SELECT login_date FROM user_streaks WHERE user_id = ? ORDER BY login_date DESC"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $user_id); $stmt->execute(); $streak_result = $stmt->get_result(); // Calculate the streak while ($row = $streak_result->fetch_assoc()) { if (!$last_login) { $last_login = $row['login_date']; $streak++; } else { $diff = (strtotime($last_login) - strtotime($row['login_date'])) / (60 * 60 * 24); // Difference in days if ($diff == 1) { $streak++; $last_login = $row['login_date']; } else if ($diff > 1) { break; // Streak breaks if the difference is more than 1 day } } } // Display the profile page ?> User Profile

User Profile

Email:

Name:

Country:

Date of Birth:

Streak: days

close(); $conn->close(); ?>