-- Host: 127.0.0.1:3306
-- Generation Time: Nov 11, 2024 at 06:48 AM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8mb4 */;
--
-- Database: u406552082_kaakalia
--
-- Table structure for table ads
CREATE TABLE ads (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
name varchar(255) NOT NULL,
ad_type enum('Post','Story') NOT NULL,
related_id int(11) NOT NULL,
budget decimal(10,2) NOT NULL,
total_spent decimal(10,2) DEFAULT 0.00,
start_date date NOT NULL,
end_date date NOT NULL,
status enum('Active','Paused','Completed') DEFAULT 'Active',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table ad_spend_logs
CREATE TABLE ad_spend_logs (
id int(11) NOT NULL,
ad_id int(11) NOT NULL,
amount decimal(10,2) NOT NULL,
spend_date datetime DEFAULT current_timestamp(),
description varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table customers
CREATE TABLE customers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
contact varchar(50) DEFAULT NULL,
delivery_address text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table drivers
CREATE TABLE drivers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
number varchar(15) NOT NULL,
is_star tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Assistant
--
-- Table structure for table notifications
CREATE TABLE notifications (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
type enum('order','post','plan','note') NOT NULL,
message varchar(255) NOT NULL,
link varchar(255) NOT NULL,
created_at datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table orders
CREATE TABLE orders (
id int(11) NOT NULL,
customer_id int(11) NOT NULL,
status enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
priority enum('Normal','Important','Quick') DEFAULT 'Normal',
order_date datetime DEFAULT current_timestamp(),
delivery_datetime datetime DEFAULT NULL,
delivery_date date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table order_items
CREATE TABLE order_items (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
product_id int(11) NOT NULL,
quantity int(11) NOT NULL DEFAULT 1,
packaging_preferences varchar(255) DEFAULT NULL,
discount_percentage decimal(5,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table products
CREATE TABLE products (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
size varchar(50) DEFAULT NULL,
price decimal(10,2) NOT NULL,
category varchar(50) DEFAULT NULL,
thumbnail varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table users
CREATE TABLE users (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
email varchar(100) DEFAULT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL,
profile_image varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_notes
CREATE TABLE workspace_notes (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
title varchar(255) NOT NULL,
content text NOT NULL,
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_plans
CREATE TABLE workspace_plans (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
title varchar(255) NOT NULL,
description text DEFAULT NULL,
audio_path varchar(255) DEFAULT NULL,
due_date datetime DEFAULT NULL,
status enum('Not Started','In Progress','Completed') DEFAULT 'Not Started',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table workspace_posts
CREATE TABLE workspace_posts (
id int(11) NOT NULL,
user_id int(11) NOT NULL,
platform enum('Instagram','Facebook','Twitter','Other') NOT NULL,
content text NOT NULL,
media_url varchar(255) DEFAULT NULL,
scheduled_datetime datetime DEFAULT NULL,
status enum('Scheduled','Posted','Failed') DEFAULT 'Scheduled',
created_at datetime DEFAULT current_timestamp(),
updated_at datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
type enum('Post','Story') DEFAULT 'Post'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE ads
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table ad_spend_logs
ALTER TABLE ad_spend_logs
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table customers
ALTER TABLE customers
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table drivers
ALTER TABLE drivers
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table notifications
ALTER TABLE notifications
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table orders
ALTER TABLE orders
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table order_items
ALTER TABLE order_items
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table products
ALTER TABLE products
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table users
ALTER TABLE users
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_notes
ALTER TABLE workspace_notes
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_plans
ALTER TABLE workspace_plans
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table workspace_posts
ALTER TABLE workspace_posts
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- Constraints for dumped tables
--
-- Constraints for table ads
ALTER TABLE ads
ADD CONSTRAINT fk_ads_related_id FOREIGN KEY (related_id) REFERENCES workspace_posts (id) ON DELETE CASCADE,
ADD CONSTRAINT fk_ads_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table ad_spend_logs
ALTER TABLE ad_spend_logs
ADD CONSTRAINT fk_ad_spend_logs_ad_id FOREIGN KEY (ad_id) REFERENCES ads (id) ON DELETE CASCADE;
--
-- Constraints for table notifications
ALTER TABLE notifications
ADD CONSTRAINT notifications_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table orders
ALTER TABLE orders
ADD CONSTRAINT fk_orders_customer_id FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT orders_ibfk_1 FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE;
--
-- Constraints for table order_items
ALTER TABLE order_items
ADD CONSTRAINT fk_order_items_order_id FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT fk_order_items_product_id FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT order_items_ibfk_1 FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE,
ADD CONSTRAINT order_items_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_notes
ALTER TABLE workspace_notes
ADD CONSTRAINT fk_workspace_notes_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_plans
ALTER TABLE workspace_plans
ADD CONSTRAINT fk_workspace_plans_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
--
-- Constraints for table workspace_posts
ALTER TABLE workspace_posts
ADD CONSTRAINT fk_workspace_posts_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) i want to appear the plans and notes and post and ad in Recent Activities, because i can't see the recente activites altghout there new plans were created, please fix it and this file activites.php (<?php
// /public/workspace/activities.php
// Enable error reporting for debugging (disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Include authentication, database connection, and utility functions
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
require_once DIR . '/../../includes/functions.php'; // Contains sanitize_input()
// Ensure the user is authenticated
if (!isset($_SESSION['user_id'])) {
header("Location: /public/login.php");
exit();
}
userid=_SESSION['user_id'];
userrole=_SESSION['role']; // 'admin' or 'staff'
$errors = [];
try {
// Fetch Plans
if (user_role === 'admin') {
plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id";
stmt=conn->prepare(plans_sql);
} else {
plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
stmt=conn->prepare(planssql);stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($plan = $result->fetch_assoc()) {
$activities[] = $plan;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for plans: " . $conn->error);
}
// Fetch Posts
if ($user_role === 'admin') {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id";
$stmt = $conn->prepare($posts_sql);
} else {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
$stmt = $conn->prepare($posts_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($post = $result->fetch_assoc()) {
$activities[] = $post;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for posts: " . $conn->error);
}
// Fetch Notes
if ($user_role === 'admin') {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id";
$stmt = $conn->prepare($notes_sql);
} else {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id
WHERE wn.user_id = ?";
$stmt = $conn->prepare($notes_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($note = $result->fetch_assoc()) {
$activities[] = $note;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for notes: " . $conn->error);
}
// Fetch Ads
if ($user_role === 'admin') {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id";
$stmt = $conn->prepare($ads_sql);
} else {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id
WHERE a.user_id = ?";
$stmt = $conn->prepare($ads_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($ad = $result->fetch_assoc()) {
$activities[] = $ad;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for ads: " . $conn->error);
}
// Fetch Notifications
if ($user_role === 'admin') {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications";
$stmt = $conn->prepare($notifications_sql);
} else {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications
WHERE user_id = ?";
$stmt = $conn->prepare($notifications_sql);
$stmt->bind_param("i", $user_id);
}
if ($stmt) {
$stmt->execute();
$result = $stmt->get_result();
while ($notification = $result->fetch_assoc()) {
$activities[] = $notification;
}
$stmt->close();
} else {
throw new Exception("Prepare statement failed for notifications: " . $conn->error);
}
// Sort activities by created_at descending
usort($activities, function ($a, $b) {
return strtotime($b['created_at']) - strtotime($a['created_at']);
});
To ensure that your Recent Activities section properly displays newly created Plans, Notes, Posts, and Ads, we'll make the following adjustments:
Suppress Error Reporting: To prevent errors from being displayed to users, we'll disable error reporting in the activities.php file.
Ensure Proper Data Fetching: Verify that all relevant activities are being fetched correctly from the database.
Provide a Comprehensive index.php: We'll create an index.php file that includes the Recent Activities section by leveraging the activities.php file.
Below are the updated codes for both activities.php and index.php.
1. Updated activities.php
Changes Made:
Disabled Error Reporting: Removed the lines that enable error reporting to prevent errors from being displayed to users.
Optimized Activity Fetching: Ensured that all activities (Plans, Posts, Notes, Ads, Notifications) are correctly fetched and included.
Sanitized Outputs: Continued using sanitize_input() to prevent XSS attacks.
Improved Activity Icons: Added more descriptive icons for better user experience.
<?php
// /public/workspace/activities.php
// Disable error reporting for production
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(0);
// Start output buffering to prevent "headers already sent" errors
ob_start();
// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()
// Ensure the user is authenticated
if (!isset($_SESSION['user_id'])) {
header("Location: /public/login.php");
exit();
}
$user_id = $_SESSION['user_id'];
$user_role = $_SESSION['role']; // 'admin' or 'staff'
$errors = [];
// Fetch all activities: Plans, Posts, Notes, Ads, Notifications
$activities = [];
try {
// Prepare and execute queries based on user role
// Helper function to execute queries
function fetch_activities($conn, $sql, $types = null, $params = []) {
$stmt = $conn->prepare($sql);
if ($stmt === false) {
throw new Exception("Prepare statement failed: " . $conn->error);
}
if ($types && $params) {
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
$result = $stmt->get_result();
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
$stmt->close();
return $data;
}
// Fetch Plans
if ($user_role === 'admin') {
$plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id";
$plans = fetch_activities($conn, $plans_sql);
} else {
$plans_sql = "SELECT wp.title AS title, wp.created_at AS created_at, u.username AS user, 'plan' AS type, CONCAT('view_plan.php?id=', wp.id) AS link
FROM workspace_plans wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
$plans = fetch_activities($conn, $plans_sql, "i", [$user_id]);
}
$activities = array_merge($activities, $plans);
// Fetch Posts
if ($user_role === 'admin') {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id";
$posts = fetch_activities($conn, $posts_sql);
} else {
$posts_sql = "SELECT CONCAT(wp.platform, ': ', wp.content) AS title, wp.created_at AS created_at, u.username AS user, 'post' AS type, CONCAT('view_post.php?id=', wp.id) AS link
FROM workspace_posts wp
JOIN users u ON wp.user_id = u.id
WHERE wp.user_id = ?";
$posts = fetch_activities($conn, $posts_sql, "i", [$user_id]);
}
$activities = array_merge($activities, $posts);
// Fetch Notes
if ($user_role === 'admin') {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id";
$notes = fetch_activities($conn, $notes_sql);
} else {
$notes_sql = "SELECT wn.title AS title, wn.created_at AS created_at, u.username AS user, 'note' AS type, CONCAT('view_note.php?id=', wn.id) AS link
FROM workspace_notes wn
JOIN users u ON wn.user_id = u.id
WHERE wn.user_id = ?";
$notes = fetch_activities($conn, $notes_sql, "i", [$user_id]);
}
$activities = array_merge($activities, $notes);
// Fetch Ads
if ($user_role === 'admin') {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id";
$ads = fetch_activities($conn, $ads_sql);
} else {
$ads_sql = "SELECT a.name AS title, a.created_at AS created_at, u.username AS user, 'ad' AS type, CONCAT('view_ad.php?id=', a.id) AS link
FROM ads a
JOIN users u ON a.user_id = u.id
WHERE a.user_id = ?";
$ads = fetch_activities($conn, $ads_sql, "i", [$user_id]);
}
$activities = array_merge($activities, $ads);
// Fetch Notifications
if ($user_role === 'admin') {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications";
$notifications = fetch_activities($conn, $notifications_sql);
} else {
$notifications_sql = "SELECT message AS title, created_at AS created_at, 'System' AS user, type AS type, link AS link
FROM notifications
WHERE user_id = ?";
$notifications = fetch_activities($conn, $notifications_sql, "i", [$user_id]);
}
$activities = array_merge($activities, $notifications);
// Sort activities by created_at descending
usort($activities, function ($a, $b) {
return strtotime($b['created_at']) - strtotime($a['created_at']);
});
} catch (Exception $e) {
// Log the error instead of displaying it
error_log($e->getMessage());
}
?>
2. Comprehensive index.php with Recent Activities
This index.php file serves as the dashboard and includes a Recent Activities section. It leverages the activities.php file to fetch and display the latest activities.
Features:
Integrated Recent Activities: Displays the latest Plans, Posts, Notes, Ads, and Notifications.
Responsive Design: Utilizes Tailwind CSS for a clean and responsive layout.
Icons and Styling: Each activity type is represented with an appropriate icon and color for easy identification.
No Error Display: Ensures that no PHP errors are shown to the end-users.
When creating new Plans, Notes, Posts, or Ads, ensure that the created_at field is automatically set using CURRENT_TIMESTAMP. This allows the activities to be correctly ordered by date.
Example for Inserting a New Plan:
<?php
// Example: Creating a new plan
// Include necessary files
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php'; // Contains sanitize_input()
// Assume form data is submitted via POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = sanitize_input($_POST['title']);
$description = sanitize_input($_POST['description']);
$due_date = sanitize_input($_POST['due_date']);
$user_id = $_SESSION['user_id'];
// Prepare and execute the insert statement
$stmt = $conn->prepare("INSERT INTO workspace_plans (user_id, title, description, due_date, created_at, updated_at) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)");
if ($stmt) {
$stmt->bind_param("isss", $user_id, $title, $description, $due_date);
if ($stmt->execute()) {
// Redirect or show success message
header("Location: activities.php");
exit();
} else {
// Handle execution error
// Log the error instead of displaying
error_log("Execution failed: " . $stmt->error);
}
$stmt->close();
} else {
// Handle preparation error
error_log("Prepare failed: " . $conn->error);
}
}
?>
b. Maintain Consistent type Values
Ensure that the type field in your activities (like notifications) aligns with the types handled in your PHP scripts. For instance, if you're using 'notification' as a type in your activities, make sure it's correctly handled in the switch statement.
c. Implement Pagination for Large Activity Sets
If your Recent Activities list grows large, consider implementing pagination or infinite scrolling to enhance performance and user experience.
d. Use Prepared Statements Everywhere
Ensure that all database interactions use prepared statements to prevent SQL injection attacks. This is already demonstrated in the activities.php and the Example for Inserting a New Plan above.
e. Regularly Log Errors
Since errors are not displayed to users, it's crucial to log them for debugging purposes. Ensure that your server's error logs are monitored, or implement a logging mechanism within your application.
f. Optimize Database Indexes
Review your database indexes to ensure optimal performance, especially on columns frequently used in WHERE, JOIN, and ORDER BY clauses.
Conclusion
By implementing the updated activities.php and comprehensive index.php files, your Recent Activities section should now accurately display newly created Plans, Notes, Posts, and Ads. Additionally, by following the best practices outlined above, you can ensure a secure, efficient, and user-friendly system.
If you encounter any further issues or have additional requirements, feel free to reach out!