-
Notifications
You must be signed in to change notification settings - Fork 0
/
receipt.php
55 lines (42 loc) · 1.39 KB
/
receipt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.html");
exit();
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user_id = $_SESSION['user_id'];
$sql = "SELECT * FROM users WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
$receipt = "User Registration Receipt\n";
$receipt .= "==========================\n\n";
$receipt .= "User ID: " . $user['id'] . "\n";
$receipt .= "Full Name: " . $user['name'] . "\n";
$receipt .= "Email: " . $user['email'] . "\n";
$receipt .= "Date of Birth: " . $user['dob'] . "\n";
$receipt .= "Age: " . $user['age'] . "\n";
$receipt .= "Job: " . $user['job'] . "\n";
$receipt .= "Address: " . $user['address'] . "\n";
$receipt .= "Phone Number: " . $user['phone'] . "\n";
$receipt .= "Registration Date: " . $user['created_at'] . "\n";
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="user_receipt.txt"');
echo $receipt;
} else {
echo "User not found.";
}
$stmt->close();
$conn->close();
?>