Good morning, I need some help with the following:
I have a form in HTML:
<form name="formulario" method="POST" action="enviar.php" enctype="multipart/form-data">
Orden nro.:
<select name="nro_pedido">
<option value="5">5</option>
</select>
<br>
Nro. de pedido:
<input name="po" id="po" type="text"/>
<br>
Cliente:
<select name="client">
<option value="CLIENTE 1">CLIENTE 1</option>
</select>
<br>
Lote: <select name="nro_lote">
<option value="EJEMPLO 1">EJEMPLO 1</option>
</select>
Factura: <input name="nro_factu" id="nro_factu" type="text"/>
<br>
<input type="submit" value="ENVIAR"/>
</form>
Then in the send.php file I receive the variables and insert them into the database:
<?php
require("conexion.php");
$conexion=conectar();
$nro_pedido=$_POST['nro_pedido'];
$po=$_POST['po'];
$client=$_POST['client'];
$nro_lote=$_POST['nro_lote'];
$nro_factu=$_POST['nro_factu'];
$sql="insert into embarques(nro_pedido,po,client,nro_lote,nro_factu)
values('$nro_pedido','$po','$client','$nro_lote','$nro_factu')";
$ok1=mysqli_query($query,$conexion);
/* PARA EJECUTAR SENTENCIAS EN LA BASE DE DATOS
UTILIZAMOS LA FUNCIÓN mysqli_query(sentencia,conexion)*/
$ok=mysqli_query($sql,$conexion);
if ($ok)
{
echo"<script type='text/javascript'>
alert('Correcto!');
window.location='formulario.php';</script>";
}
else
{
echo "<script>alert('Error')
window.location='formulario.php';</script>";
}
?>
When I press the SEND button, the form data goes to the file -send.php- there I only receive the variables and then I do an insert in the database table, now how can I do so that when inserting the data then Generate a pdf file with the same registered data and send it to a specific email through the languages I am using:
PHP, HTML, MySQL
I am doing this locally and I am using xampp and phpmyadmin.
After inserting the data you can use a package to generate a PDF, if it's something simple you can use DomPDF ( https://github.com/dompdf/dompdf ), install it using composer:
In case you are not using composer, as I can see in the code you paste, you can download the latest release ( https://github.com/dompdf/dompdf/releases ) and paste it in the directory, then do a require:
I suggest you read the documentation to be able to generate the PDF file you require, but the steps are simple:
To send the email, I suggest you use PHPMailer ( https://github.com/PHPMailer/PHPMailer ), to send the email the steps are similar to dompdf, also, I suggest reviewing the documentation but for something simple this is enough (Don't forget the require or installation via composer):