diff --git a/db/migrations/002_create_competition_participants.sql b/db/migrations/002_create_competition_participants.sql new file mode 100644 index 0000000..d9b5dca --- /dev/null +++ b/db/migrations/002_create_competition_participants.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS `competition_participants` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` INT NOT NULL, + `competition_id` INT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`competition_id`) REFERENCES `competitions`(`id`) ON DELETE CASCADE, + UNIQUE KEY `user_competition` (`user_id`, `competition_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/db/migrations/003_create_competition_submissions.sql b/db/migrations/003_create_competition_submissions.sql new file mode 100644 index 0000000..888f991 --- /dev/null +++ b/db/migrations/003_create_competition_submissions.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS `competition_submissions` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` INT NOT NULL, + `competition_id` INT NOT NULL, + `file_path` VARCHAR(255) NOT NULL, + `uploaded_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`competition_id`) REFERENCES `competitions`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/join_competition.php b/join_competition.php new file mode 100644 index 0000000..094468a --- /dev/null +++ b/join_competition.php @@ -0,0 +1,25 @@ +prepare("INSERT INTO competition_participants (user_id, competition_id) VALUES (?, ?)"); + $stmt->execute([$user_id, $competition_id]); + } catch (PDOException $e) { + // Handle potential errors, like trying to join the same competition twice + // You might want to log this error or show a message + } +} + +header("location: user_dashboard.php"); +exit; diff --git a/login.php b/login.php index 8af845c..121b1b8 100644 --- a/login.php +++ b/login.php @@ -23,6 +23,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $stmt->execute([$email]); $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['user_name'] = $user['name']; @@ -125,7 +127,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
-