HyperOsmar
Member
Dear colleagues,
I'm inserting the code below into a form, using the PHP plugin with the "End of form submission (onAfterProcess) option:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
// Connection to the MySQL database
$conn = new mysqli('localhost', 'xxxxxx', 'xxxxxx', 'xxxxxx');
// Check if the connection was successful
if ($conn->connect_error) {
die("Failed to connect to database: " . $conn->connect_error);
}
// Retrieve user data from database
$sql = "SELECT * FROM users WHERE id = 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
// Define user information in variables
$name = $row['cod_cnes'];
$email = $row['establishment_name'];
$phone = $row['mun_name'];
// Create a new Dompdf object
$dompdf = new Dompdf();
// Defines the HTML content of the PDF file
$html = '<h1>User Data</h1>';
$html .= '<p><strong>Municipality Code:</strong> ' . $name . '</p>';
$html .= '<p><strong>Establishment Name:</strong> ' . $email . '</p>';
$html .= '<p><strong>County Name:</strong> ' . $phone . '</p>';
// Load HTML content into the Dompdf object
$dompdf->loadHtml($html);
// Render the HTML content in a PDF file
$dompdf->render();
// Set password protection for the PDF file
$password = '123456';
// Protect the PDF file with the defined password
$dompdf->getCanvas()->get_cpdf()->setEncryption($password, $password);
// Defines the name of the generated PDF file
$filename = 'user_data.pdf';
// Send the generated PDF file to the browser
$dompdf->stream($filename, array('Attachment' => 0));
} else {
echo "No user found in database.";
}
// Close the database connection
$conn->close();
?>
and the following error appears:
0
syntax error, unexpected token "<"
Can someone help me???...
I'm inserting the code below into a form, using the PHP plugin with the "End of form submission (onAfterProcess) option:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
// Connection to the MySQL database
$conn = new mysqli('localhost', 'xxxxxx', 'xxxxxx', 'xxxxxx');
// Check if the connection was successful
if ($conn->connect_error) {
die("Failed to connect to database: " . $conn->connect_error);
}
// Retrieve user data from database
$sql = "SELECT * FROM users WHERE id = 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
// Define user information in variables
$name = $row['cod_cnes'];
$email = $row['establishment_name'];
$phone = $row['mun_name'];
// Create a new Dompdf object
$dompdf = new Dompdf();
// Defines the HTML content of the PDF file
$html = '<h1>User Data</h1>';
$html .= '<p><strong>Municipality Code:</strong> ' . $name . '</p>';
$html .= '<p><strong>Establishment Name:</strong> ' . $email . '</p>';
$html .= '<p><strong>County Name:</strong> ' . $phone . '</p>';
// Load HTML content into the Dompdf object
$dompdf->loadHtml($html);
// Render the HTML content in a PDF file
$dompdf->render();
// Set password protection for the PDF file
$password = '123456';
// Protect the PDF file with the defined password
$dompdf->getCanvas()->get_cpdf()->setEncryption($password, $password);
// Defines the name of the generated PDF file
$filename = 'user_data.pdf';
// Send the generated PDF file to the browser
$dompdf->stream($filename, array('Attachment' => 0));
} else {
echo "No user found in database.";
}
// Close the database connection
$conn->close();
?>
and the following error appears:
0
syntax error, unexpected token "<"
Can someone help me???...