<?
php
//MySQL connection
$servername = "localhost";
$username = "root";
$password = "Peron100906@";
$dbname = "event_registration";
//variables
$purchaseId = "";
$purchaseDetails = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$purchaseId = $_POST['purchase_id'];
//create MySQL connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//search for the purchase ID in the database
$search = $conn->prepare("SELECT * FROM purchases WHERE purchase_id = ?");
$search->bind_param("s", $purchaseId);
$search->execute();
$result = $search->get_result(); //add the output to "result"
//if it returns at least one row:
if ($result->num_rows > 0) {
//fetch the purchase details
$purchaseDetails = $result->fetch_assoc();
} else {
$purchaseDetails = "No purchase found with this ID.";
}
//Close the connection
$search->close();
$conn->close();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Find your purchase">
<title>Find Your Purchase</title>
<link rel="stylesheet" href="./CSS/style.css">
</head>
<body>
<div id="main-div">
<h2>Find Your Purchase</h2>
<!--form to find purchase by ID-->
<form method="POST">
<div class="form-group">
<label for="purchase_id">Enter Your Purchase ID</label><br>
<input type="text" id="purchase_id" name="purchase_id" required>
</div>
<button type="submit" id="btn">Find Purchase</button>
</form>
<!--Display purchase details if found-->
<?php if ($purchaseDetails): ?>
<div class="purchase-details">
<?php
if (is_array($purchaseDetails)) {
echo "<p><strong>Name:</strong> " . htmlspecialchars($purchaseDetails['name']) . "</p>";
echo "<p><strong>Email:</strong> " . htmlspecialchars($purchaseDetails['email']) . "</p>";
echo "<p><strong>Ticket Count:</strong> " . htmlspecialchars($purchaseDetails['ticket_count']) . "</p>";
echo "<p><strong>Total Price:</strong> $" . htmlspecialchars($purchaseDetails['total_price']) . "</p>";
echo "<p><strong>Purchase ID:</strong> " . htmlspecialchars($purchaseDetails['purchase_id']) . "</p>";
echo "<p><strong>Purchase Date:</strong> " . htmlspecialchars($purchaseDetails['purchase_date']) . "</p>";
} else {
echo "<p>" . htmlspecialchars($purchaseDetails) . "</p>";
}
?>
</div>
<?php endif; ?>
</div>
</body>
</html>