0% found this document useful (0 votes)
2 views

index.php

This PHP document handles event registration by collecting user information and ticket details through a form. It calculates the total price based on the number of tickets and generates a unique purchase ID before inserting the data into a MySQL database. The HTML structure includes input fields for user details and displays the total price and purchase ID after submission.

Uploaded by

Joao Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

index.php

This PHP document handles event registration by collecting user information and ticket details through a form. It calculates the total price based on the number of tickets and generates a unique purchase ID before inserting the data into a MySQL database. The HTML structure includes input fields for user details and displays the total price and purchase ID after submission.

Uploaded by

Joao Pedro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php

//MySQL information
$servername = "localhost";
$username = "root";
$password = "Peron100906@";
$dbname = "event_registration";

//Variables
$totalPrice = 0;
$ticketCount = 0;
$name = "";
$email = "";
$purchaseId = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
//get the amount of tickets and calculate the final price
$ticketCount = isset($_POST['tickets']) ? intval($_POST['tickets']) : 0;
$pricePerTicket = 30; //ticket price
$totalPrice = $ticketCount * $pricePerTicket;

//cenerate a ticket id of 6 characters (letters and numbers)


$purchaseId = strtoupper(bin2hex(random_bytes(4)));

$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);

//create MySQL connection


$conn = new mysqli($servername, $username, $password, $dbname);

//check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

//prepare and bind the insert query


$insert = $conn->prepare("INSERT INTO purchases (name, email, ticket_count, total_price, purchase_id) VALUES (?, ?, ?, ?, ?)");
$insert->bind_param("ssids", $name, $email, $ticketCount, $totalPrice, $purchaseId);

//execute the query


if ($insert->execute()) {

} else {
echo "Error: " . $insert->error;
}

//close the connection


$insert->close();
$conn->close();
}

?>

<!doctype html>
<html lang="en">

<head>
<!--Meta datas-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Event Registration">
<title>PHP-Project</title>
<meta name="robots" content="noindex, nofollow">
<!--My CSS file-->
<link rel="stylesheet" href="./CSS/style.css">
</head>

<body>

<div id="main-div">
<img src="./IMG/ShowPoster.avif">

<div id="form-container">
<h2>Event Registration</h2>
<!--Button to navigate to Find Your Purchase page-->
<a href="find_purchase.php" id="find-purchase-btn">
<button class="btn" type="button">Find your purchase</button>
</a>
<form method="POST">
<!--Name field-->
<div class="form-group">
<label for="name">Full Name</label><br>
<input type="text" id="name" name="name" required>
</div>
<!--Card Number field-->
<div class="form-group">
<label for="card_number">Card Number</label><br>
<input type="text" id="card_number" name="card_number" maxlength="16" pattern="\d{16}" placeholder="1234 5678 9012 3456" required>
</div>
<!--CVV field-->
<div class="form-group">
<label for="cvv">CVV</label><br>
<input type="text" id="cvv" name="cvv" maxlength="3" pattern="\d{3}" placeholder="123" required>
</div>
<!--Expiration Date field-->
<div class="form-group">
<label for="expiry_date">Date</label><br>
<input type="date" id="expiry_date" name="expiry_date" required>
</div>
<!--Number of Tickets field-->
<div class="form-group">
<label for="tickets">Number of Tickets</label><br>
<input type="number" id="tickets" name="tickets" min="1" max="10" value="<?php echo $ticketCount; ?>" required>
</div>
<!--Email field-->
<div class="form-group">
<label for="email">Email</label><br>
<input type="email" id="email" name="email" required><br>
</div>
<!--Submit Button-->
<button type="submit" class="btn">Register</button>
</form>

<!--Display Total Price-->


<div class="total-price">
<?php if ($ticketCount > 0): ?>
<p>Total Price: $<?php echo $totalPrice; ?></p>
<?php endif; ?>
</div>

<!--Display Purchase ID-->


<div class="purchase-id">
<?php if ($purchaseId): ?>
<p>Your Purchase ID: <?php echo $purchaseId; ?></p>
<?php endif; ?>
</div>

</div>
</div>

</body>

</html>

You might also like