diff --git a/assets/css/custom.css b/assets/css/custom.css index ef21950..e2c9216 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -121,16 +121,17 @@ main.container { margin-bottom: 0.5rem; } -.form-group input { +.form-group input, .form-group textarea { width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--color-border); border-radius: 0.5rem; font-size: 1rem; transition: border-color 0.2s ease, box-shadow 0.2s ease; + background-color: var(--color-background); } -.form-group input:focus { +.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3); @@ -337,4 +338,67 @@ main.container { .style-sketch { filter: grayscale(1) brightness(1.2) contrast(1.5); -} \ No newline at end of file +} + +/* Comments Section */ +.comments-container { + max-width: 800px; + margin: 4rem auto 2rem; + text-align: left; +} + +.comments-title { + font-size: 1.75rem; + font-weight: 700; + margin-bottom: 1.5rem; + text-align: center; +} + +.comment-form-wrapper { + background-color: var(--color-surface); + padding: 1.5rem; + border-radius: var(--border-radius); + box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); + margin-bottom: 2rem; +} + +.comment-form-wrapper textarea { + min-height: 80px; + resize: vertical; +} + +.comment-form-wrapper .btn { + margin-top: 1rem; +} + +.comments-list { + display: flex; + flex-direction: column; + gap: 1.5rem; +} + +.comment-card { + background-color: var(--color-surface); + padding: 1.5rem; + border-radius: var(--border-radius); + box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); +} + +.comment-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 1rem; + font-size: 0.9rem; + color: var(--color-text-muted); +} + +.comment-author { + font-weight: 600; + color: var(--color-text); +} + +.comment-body p { + margin: 0; + line-height: 1.6; +} diff --git a/db/migrations/001_create_users_table.php b/db/migrations/001_create_users_table.php index 51dad71..86b7ca7 100644 --- a/db/migrations/001_create_users_table.php +++ b/db/migrations/001_create_users_table.php @@ -1,22 +1,26 @@ exec($sql); - - echo "Migration 001: users table created or already exists." . PHP_EOL; - -} catch (PDOException $e) { - die("Migration failed: " . $e->getMessage()); -} \ No newline at end of file + try { + $pdo = db(); + $sql = " + CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + "; + $pdo->exec($sql); + echo "Migration 001: 'users' table created or already exists.\n"; + } catch (PDOException $e) { + die("Migration 001 failed: " . $e->getMessage() . "\n"); + } +} diff --git a/db/migrations/002_create_comments_table.php b/db/migrations/002_create_comments_table.php index a561a99..1245a2b 100644 --- a/db/migrations/002_create_comments_table.php +++ b/db/migrations/002_create_comments_table.php @@ -1,25 +1,27 @@ exec($sql); - echo "Migration 002: Comments table created successfully.\n"; + echo "Migration 002: 'comments' table created or already exists.\n"; } catch (PDOException $e) { die("Migration 002 failed: " . $e->getMessage() . "\n"); } } - diff --git a/index.php b/index.php index 96fbef0..e40e365 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,39 @@ prepare("INSERT INTO comments (user_id, comment) VALUES (:user_id, :comment)"); + $stmt->execute(['user_id' => $_SESSION['user_id'], 'comment' => $comment_text]); + } catch (PDOException $e) { + // Optional: handle error, e.g., log it or show a generic error message + } + } + // Redirect to the same page to prevent form resubmission + header("Location: index.php"); + exit; +} + +// Fetch comments +$comments = []; +if (isset($_SESSION['user_id'])) { + try { + $stmt = db()->query(" + SELECT c.comment, c.created_at, u.username + FROM comments c + JOIN users u ON c.user_id = u.id + ORDER BY c.created_at DESC + "); + $comments = $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + // Optional: handle error + } +} + ?> @@ -48,6 +81,39 @@ require_once 'partials/header.php'; + + +
Community Feedback
+No comments yet. Be the first to share your thoughts!
+ + +