Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
include "db.php";
echo "<h1>Setting Up List Likes Feature</h1>";
try {
// Create the list_likes table if it doesn't exist
$conn->exec("
CREATE TABLE IF NOT EXISTS list_likes (
id INT AUTO_INCREMENT PRIMARY KEY,
list_id INT NOT NULL,
user_id INT NOT NULL,
is_like TINYINT(1) NOT NULL DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (list_id) REFERENCES word_lists(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY unique_user_list (user_id, list_id)
)
");
echo "✅ Created list_likes table successfully<br>";
// Add like_count and dislike_count columns to word_lists table for quicker counts
$result = $conn->query("SHOW COLUMNS FROM word_lists LIKE 'like_count'");
if ($result->rowCount() == 0) {
$conn->exec("ALTER TABLE word_lists ADD COLUMN like_count INT NOT NULL DEFAULT 0");
echo "✅ Added like_count column to word_lists table<br>";
} else {
echo "✅ like_count column already exists in word_lists table<br>";
}
$result = $conn->query("SHOW COLUMNS FROM word_lists LIKE 'dislike_count'");
if ($result->rowCount() == 0) {
$conn->exec("ALTER TABLE word_lists ADD COLUMN dislike_count INT NOT NULL DEFAULT 0");
echo "✅ Added dislike_count column to word_lists table<br>";
} else {
echo "✅ dislike_count column already exists in word_lists table<br>";
}
echo "<p>Setup complete! Users can now like or dislike lists in the List Hub.</p>";
echo "<p>Visit <a href='list_hub.php'>List Hub</a> to explore and rate public lists.</p>";
} catch (PDOException $e) {
echo "❌ Error: " . $e->getMessage() . "<br>";
}
?>