Update ticket processing and database schema: modify category options, add day field, and adjust SQL insert statement

This commit is contained in:
vista-man
2025-04-10 21:20:07 +02:00
parent f4cc70f5bb
commit 4f9d6d4428
2 changed files with 10 additions and 4 deletions

View File

@@ -7,7 +7,8 @@ CREATE TABLE tickets (
ticket_id VARCHAR(255) NOT NULL UNIQUE, ticket_id VARCHAR(255) NOT NULL UNIQUE,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
category ENUM('adult', 'child', 'group') NOT NULL, category ENUM('volwassen', 'kind') NOT NULL,
day ENUM('friday', 'saturday') NOT NULL,
quantity INT NOT NULL, quantity INT NOT NULL,
qr_code_link VARCHAR(255), qr_code_link VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

View File

@@ -21,9 +21,14 @@ if ($conn->connect_error) {
// Retrieve form data // Retrieve form data
$name = $_POST['name']; $name = $_POST['name'];
$email = $_POST['email']; $email = $_POST['email'];
$category = $_POST['category']; $category = $_POST['category']; // e.g., 'Volwassenen Vrijdag' or 'Kinderen Zaterdag'
$quantity = (int)$_POST['quantity']; $quantity = (int)$_POST['quantity'];
// Extract day and category from the input
list($categoryType, $day) = explode(' ', $category); // Split into 'Volwassenen'/'Kinderen' and 'Vrijdag'/'Zaterdag'
$day = strtolower($day) === 'vrijdag' ? 'friday' : 'saturday';
$categoryType = strtolower($categoryType) === 'volwassenen' ? 'volwassen' : 'kind';
require __DIR__ . '/../phpmailer/src/PHPMailer.php'; require __DIR__ . '/../phpmailer/src/PHPMailer.php';
require __DIR__ . '/../phpmailer/src/SMTP.php'; require __DIR__ . '/../phpmailer/src/SMTP.php';
require __DIR__ . '/../phpmailer/src/Exception.php'; require __DIR__ . '/../phpmailer/src/Exception.php';
@@ -32,7 +37,7 @@ use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\Exception;
// Prepare SQL statement // Prepare SQL statement
$sql = "INSERT INTO tickets (ticket_id, name, email, category, quantity, qr_code_link) VALUES (?, ?, ?, ?, ?, ?)"; $sql = "INSERT INTO tickets (ticket_id, name, email, category, day, quantity, qr_code_link) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
if (!$stmt) { if (!$stmt) {
@@ -46,7 +51,7 @@ for ($i = 0; $i < $quantity; $i++) {
$ticket_id = bin2hex(random_bytes(16)); // Generate a 32-character unique ticket ID $ticket_id = bin2hex(random_bytes(16)); // Generate a 32-character unique ticket ID
$qrCodeUrl = "https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=" . urlencode($ticket_id); // Generate QR code link $qrCodeUrl = "https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=" . urlencode($ticket_id); // Generate QR code link
$one_ticket_quantity = 1; // Each row represents one ticket $one_ticket_quantity = 1; // Each row represents one ticket
$stmt->bind_param("ssssss", $ticket_id, $name, $email, $category, $one_ticket_quantity, $qrCodeUrl); $stmt->bind_param("sssssis", $ticket_id, $name, $email, $categoryType, $day, $one_ticket_quantity, $qrCodeUrl);
if (!$stmt->execute()) { if (!$stmt->execute()) {
echo "Error: " . $stmt->error; echo "Error: " . $stmt->error;
$stmt->close(); $stmt->close();