Generate a PDF and write data to the database in the same form

Asked

Viewed 374 times

0

I have a program that takes the name and email of the client to register in the bank and generate a pdf with this data. But I can’t send the registration data to the file that generates the pdf. Either the registration works in the bank or the pdf works. I’ve used Ajax to submit to different files but it doesn’t work. The ideal would be to generate the pdf after writing this data in the database but also does not work.

Form:

<form action="incluirProfessor.php" method="POST"> 
<!--Entrada dados --> 
<label for="nomeprof"> Nome: </label> <input name="nomeprof" type="text"/>
<label for="emailprof">eMail: </label> <input name="emailprof" type="email"/>
<input type="submit" name="Convidar" value="Convidar" /> 
</form>

Include:

  // incluirProfessor.php

  require 'conexao.php';
  if (isset($_POST["Convidar"])) {

  mysqli_query($con, "SET NAMES 'utf8'");

  $nome  = $_POST["nomeprof"];
  $email = $_POST["emailprof"];

  // Guardando a instrução sql para inclusao
  $sqlinc = "insert into professor(Prof_Nome,Prof_Email) values ('$nome','$email')";

  // submetendo inserção à conexão, se algo der errado paramos a execução com DIE

  if ($con->query($sqlinc) === TRUE) {
  echo "<script>alert('Cadastro realizado com sucesso!'); </script>";
  } else {
  echo "<script>alert('Ocorreu algum erro! Seu cadastro não foi concluído com sucesso.');</script>";
  echo "Error deleting record: " .$con->error;
  }
  mysqli_close($con); 
  exit;
}

PDF:

<?php   
use Dompdf\Dompdf; 
require_once("dompdf/autoload.inc.php"); 
$dompdf = new DOMPDF(); 
$nomeprof = $_POST["nomeprof"]; 
$emailprof = $_POST["emailprof"]; 
$data_envio = date('d/m/Y'); 
$from = "[email protected]"; 
$subject = "Convite para o sistema InfoQT"; 
$site = "www.infoqt.com.br"; 
$dompdf->load_html("Mensagem enviada"); 
$dompdf->render(); //Exibibir a página 
$dompdf->stream( "relatorio_celke.pdf", array( "Attachment" => false //Para realizar o download somente alterar para true ) ); ?>
  • Show your code so it’s easier to help you.

  • The first is the form of the program. The second is include. They both work perfectly without the PDF. With the PDF it n works.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.