Home About Projects
← Back to Home

Mindful Moments

Project screenshot

🌿 Mindful Moments

A personal mood tracking app for self‑reflection and emotional awareness.


✨ Overview

Mindful Moments is a full‑stack Mood Tracker application designed to help users monitor and reflect on their emotional well‑being over time.
Built with PHP, HTML, CSS, and SQL, it follows the MVC architecture for clean, maintainable, and scalable code.


🔐 Key Features

  • 👤 User Accounts – Create an account and log in securely with hashed passwords.
  • 📊 Mood Visualization – Track your moods over time with interactive charts powered by Chart.js.
  • 🗂 Organized Data Flow – MVC pattern ensures consistent and efficient data handling.
  • 💻 Local Hosting – Runs on Apache via WAMP Server for easy local development.

🛠 Tech Stack

LayerTechnology
FrontendHTML, CSS, JavaScript
BackendPHP (MVC Pattern)
DatabaseMySQL / SQL
ChartsChart.js
ServerApache (WAMP)

📈 How It Works

  1. Sign Up / Log In – Users register with a unique username and secure password.
  2. Log Your Mood – Select your mood and add a note.
  3. View Trends – Chart.js displays mood patterns over days, weeks, or months.
  4. Reflect & Improve – Use insights to make mindful lifestyle adjustments.

🗄 Database Schema

Below is the SQL script used to create and configure the Mindful Moments database, including tables for users and mood entries, as well as an admin user with appropriate permissions.

-- Create the mindful_moments database
DROP DATABASE IF EXISTS mindful_moments;
CREATE DATABASE mindful_moments;
USE mindful_moments;

-- Create tables
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR(100) NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE entries (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    mood VARCHAR(50) NOT NULL,
    notes TEXT,
    entry_date DATE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

-- Create Admin User
DROP USER IF EXISTS 'mindful_moments_admin'@'localhost';
CREATE USER 'mindful_moments_admin'@'localhost' IDENTIFIED BY 'pickl3dp!zz@';

GRANT SELECT, INSERT, DELETE, UPDATE, ALTER
ON mindful_moments.*
TO mindful_moments_admin@localhost;

🔑 Registration Logic (PHP)

Below is the PHP script that handles user registration, including input sanitization, password hashing, and secure database insertion.

<?php
require_once('../includes/utils.php');

# Grab entered registration values and sanitize them accordingly
$username = sanitizeInput($_POST['username']);
$email = filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL);
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];

# Ensure password and confirm_password match (just in case someone case disable)
# javascript in the browser)
if ($password !== $confirm_password) {
    echo "<p style='color: red;'>❌ Passwords do not match. Please try again.</p>";
} else {
    require_once('../db/database.php');
    $password_hash = password_hash($password, PASSWORD_DEFAULT);

    $query = 'INSERT INTO users
                (username, email, password_hash)
            VALUES
                (:username, :email, :password)';
    $statement = $pdo->prepare($query);
    $statement->bindValue(':username', $username);
    $statement->bindValue(':email', $email);
    $statement->bindValue(':password', $password_hash);

    try {
        $statement->execute();

        # header gives the browser a clear redirect
        # better to use than include. Also prevents form submission
        # on refresh
        header('Location: ../authPages/registrationComplete.php');
        exit;
    } catch (PDOException $e) {
        echo "<p style='color: red;'>⚠️ Error: " . $e->getMessage() . "</p>";
    }
    
}
?>

🔓 Login Logic (PHP)

Below is the PHP script that handles user login, including input sanitization, password verification, and session management.

<?php
require_once('../db/database.php');
require_once('../includes/utils.php');

# Grab entered login values and sanitize
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$password = $_POST['password'];

try {
    # Prepare query, fetch user
    $query = 'SELECT * FROM users
            WHERE email = :email';
    $statement = $pdo->prepare($query);
    $statement->bindValue(':email', $email);
    $statement->execute();
    $user = $statement->fetch();

    # Verify password and complete log in
    if ($user && password_verify($password, $user['password_hash'])) {
        session_start();
        $_SESSION['user_id'] = $user['id'];
        $_SESSION['username'] = $user['username'];

        # Go to dashboard page upon successful login
        header('Location: ../index.php?page=dashboard');
        exit;
    } else {
        echo "<p style='color: red;'>❌ Invalid login. Try again.</p>";
    }
} catch (PDOException $e) {
    echo "<p style='color: red;'>⚠️ Error: " . $e->getMessage() . "</p>";
}
?>

🚪 Logout Logic (PHP)

Below is the PHP script that handles logging a user out by destroying their session and redirecting them to the login page.

<?php

// Destroy the session
session_start();
$_SESSION = array();
destroySession();

// Redirect to login page after logout
header('Location: /mindful-moments/index.php?page=login');
exit;

?>

🧭 Main Controller – index.php

This is the central controller for the Mindful Moments application.
It handles routing between pages based on the page query parameter, includes shared layout components, and manages session state for login/logout.

<?php
require_once('includes/session.php');
require_once('includes/utils.php');
require_once('db/database.php');

include('includes/header.php');
include('includes/nav.php');

$page = $_GET['page'] ?? 'login';
$action = $_GET['action'] ?? 'logout';

switch($page) {
    case 'register':
        include('authPages/register.php');
        break;
    case 'login':
        $_SESSION = array();
        session_destroy();
        include('authPages/login.php');
        break;
    case 'logout':
        include('authLogic/logout.php');
    case 'dashboard':
        include('pages/dashboard.php');
        break;
    case 'newEntry': 
        include('pages/newEntry.php');
        break;
    case 'editEntry':
        include('pages/editEntry.php');
}

include('includes/footer.php');
?>

🎯 Purpose

The goal of Mindful Moments is to empower users to understand their emotional patterns,
helping them make informed decisions to improve mental well‑being.


🚀 Future Enhancements

  • 📱 Mobile‑friendly responsive design
  • 📅 Calendar view for mood entries
  • ☁️ Cloud hosting for remote access
  • 🔔 Mood logging reminders

“What gets measured, gets improved.” – Peter Drucker
Mindful Moments makes it easy to measure your moods and take steps toward a healthier, happier you.