26 lines
731 B
PHP
26 lines
731 B
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header("location: login.php");
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['competition_id'])) {
|
|
$user_id = $_SESSION['user_id'];
|
|
$competition_id = $_POST['competition_id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->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;
|