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(); } // Insert login date into user_streaks table $today = date('Y-m-d'); // Check if the user logged in today $checkStreak = $conn->query("SELECT * FROM user_streaks WHERE user_id = $user_id AND login_date = '$today'"); if ($checkStreak->num_rows == 0) { // Insert new login date $conn->query("INSERT INTO user_streaks (user_id, login_date) VALUES ($user_id, '$today')"); } $stmt->close(); $conn->close(); ?>