33 lines
773 B
PHP
33 lines
773 B
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
if (!isset($_GET['id'])) {
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$event_id = $_GET['id'];
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
try {
|
|
$conn = db();
|
|
$stmt = $conn->prepare("INSERT INTO tickets (user_id, event_id) VALUES (:user_id, :event_id)");
|
|
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
|
|
$stmt->bindParam(':event_id', $event_id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
|
|
header('Location: my_tickets.php?success=ticket_purchased');
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
// Handle database error
|
|
header('Location: event_details.php?id=' . $event_id . '&error=db_error');
|
|
exit();
|
|
}
|