-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprint_report.php
More file actions
100 lines (96 loc) · 2.89 KB
/
Copy pathprint_report.php
File metadata and controls
100 lines (96 loc) · 2.89 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once('TCPDF-main/tcpdf.php');
$servername = "localhost";
$username = "root";
$password = "";
$database = "db_webuild";
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if(isset($_POST['print'])) {
$id = $_POST['id'];
$sql = "SELECT * FROM Submit WHERE id = $id";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
$pdf_content = "
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
.title {
text-align: center;
}
</style>
</head>
<body>
<div class='title'>
<h1>WeBuild</h1>
<h2>BOOKING REPORT</h2>
</div>
<table>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<tr>
<td>Name</td>
<td>" . $row['name'] . "</td>
</tr>
<tr>
<td>Email</td>
<td>" . $row['email'] . "</td>
</tr>
<tr>
<td>Number</td>
<td>" . $row['number'] . "</td>
</tr>
<tr>
<td>Location</td>
<td>" . $row['location'] . "</td>
</tr>
<tr>
<td>Message</td>
<td>" . $row['message'] . "</td>
</tr>
<tr>
<td>Services</td>
<td>" . $row['services'] . "</td>
</tr>
</table>
</body>
</html>
";
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle('Report');
$pdf->SetSubject('Report');
$pdf->SetKeywords('Report, PDF, Download');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();
$pdf->writeHTML($pdf_content, true, false, true, false, '');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="report.pdf"');
echo $pdf->Output('report.pdf', 'D');
exit();
} else {
echo "Error: Record not found.";
}
} else {
echo "Error: Invalid request.";
}
?>