0
I have a report created in mPDF that performs a select through the following function that is found on the page "registra_pessoa.php":
include_once("registra_pessoa.php");
$pessoas = filtraPessoas();
Follows function:
function filtraPessoas(){
$grupo = '';
$banco = abrirBanco();
if(isset($_POST['nomefiltrar'])){
$teste = $_POST['nomefiltrar'];
}else{
$teste = '';
}
$sql = "SELECT id, nome, DATE_FORMAT(nascimento, '%d/%m/%Y') AS data_formatada, endereco, telefone FROM pessoa WHERE nome LIKE '%$teste%' ";
$resultado = $banco->query($sql);
$banco->close();
while($row = mysqli_fetch_array($resultado)){
$grupo[] = $row;
}
return $grupo;
}
Through the "name filter" field, the report should filter, however, I realized that the variable '$test' is not receiving the value contained in the field.
I tried to include once('query clients.php') (page containing this field), but returns error because mPDF uses its own tags from , etc:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\despesas\consulta_clientes.php:180) in C:\xampp\htdocs\despesas\MPDF57\mpdf.php on line 7447
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\despesas\consulta_clientes.php:180) in C:\xampp\htdocs\despesas\MPDF57\mpdf.php on line 1736
mPDF error: Some data has already been output to browser, can't send PDF file
Follows form:
<div class="container">
<form hidden name="filtroClientes" action="consulta_clientes.php" method="POST">
<div class="form-group row">
<label for="nomefiltrar" style="color:#E4CDAC; font-size: 17px; font-family:Arial">Nome</label>
<p>
<input type="text" class="teste" id="nomefiltrar" name="nomefiltrar" />
</div>
<input type="hidden" name="acao" value="filtrar" />
<button type="submit" class="btn btn-custom btn-roxo">Filtrar</button>
</div>
</form>
@Edit:
consulta_clientes.php :
<?php include_once("registra_pessoa.php");
$grupo = filtraPessoas();
if(!$_SESSION['usuario']){
header('Location: index.php?erro=1');
}
?>
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<script type="text/javascript">
function ocultaForm(tag){
$(tag).show();
}
</script>
<meta charset="UTF-8">
<title>Despesas</title>
<!-- jquery - link cdn -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script type="text/javascript" src="js/jquery.mask.min.js"/></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- bootstrap - link cdn -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="estilo.css" rel="stylesheet">
</head>
<body>
<!-- Static navbar -->
<nav class="navbar navbar-fixed-top navbar-inverse navbar-transparente">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#barranavegacao">
<span class="sr-only">Alternar navegação</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="home.php" class="navbar-brand">
<span class="img-logo">Despesas</span>
</a>
</div>
<div class="collapse navbar-collapse" id="barranavegacao">
<ul class="nav navbar-nav">
<li><a href="home.php">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Cadastro
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="inserir_pessoa.php">Cadastro de Clientes</a></li>
<li><a href="inserir_produto.php">Cadastro de Produtos</a></li>
</ul>
</li>
<li class="dropdown active">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Consultas
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="consulta_clientes.php">Consulta de Clientes</a></li>
<li><a href="consulta_produtos.php">Consulta de Produtos</a></li>
<li role="separator" class="divider"></li>
<li><a href="consulta_contas.php">Consulta de Contas a Pagar</a></li>
<li><a href="consulta_contas_receber.php">Consulta de Contas a Receber</a></li>
</ul>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Financeiro
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="inserir_conta.php">Contas a Pagar</a></li>
<li><a href="inserir_recebimento.php">Contas a Receber</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="">Ajuda</a>
</li>
<li class="divisor" role="separator">
</li>
<li>
<a href="sair.php">Sair</a>
</li>
</ul>
</div>
</div>
</nav>
<br><br><br><br><br>
<div class="container">
<div class="thumb">
<a href="pdf_clientes.php" target="_blank">
<img src="imagens/printer.png">
</a>
<div class="desc"><span style="color:white">Imprimir Relatório</span></div>
</div>
<div class="thumb">
<img id="filtraresultados" name="filtraresultados" src="imagens/search.png" style="cursor:pointer" "/>
<div class="desc"><span style="color:white">Filtrar Resultados</span></div>
</div>
</div>
<br>
<div class="container">
<form hidden name="filtroClientes" action="consulta_clientes.php" method="POST">
<div class="form-group">
<label for="nomefiltrar" style="color:#E4CDAC; font-size: 17px; font-family:Arial">Nome</label>
<p>
<input type="text" class="teste" id="nomefiltrar" name="nomefiltrar" />
</div>
<input type="hidden" name="acao" value="filtrar" />
<button type="submit" class="btn btn-custom btn-roxo">Filtrar</button>
</div>
</form>
<br>
<script>
filtraresultados.addEventListener("click", function() {
ocultaForm('form');
}, false);
</script>
<script>
filtraresultados.addEventListener("click", function() {
ocultaFormBotao('input');
}, false);
</script>
<div class="container divconsultas">
<table class="table">
<thread>
<tr>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Nome</td>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Data de nascimento</td>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Telefone</td>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Endereço</td>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Editar</td>
<td align="center" style="color:white; font-size: 17px; font-family:Tahoma">Excluir</td>
</tr>
</thread>
<?php
if (is_array($grupo) || is_object($grupo)){
foreach($grupo as $pessoa){
?>
<tr>
<td align="center" style="color:white; font-size: 15px; font-family:Tahoma"> <?=$pessoa["nome"]?> </td>
<td align="center" style="color:white; font-size: 15px; font-family:Tahoma"> <?=$pessoa["data_formatada"]?> </td>
<td align="center" style="color:white; font-size: 15px; font-family:Tahoma"> <?=$pessoa["telefone"]?> </td>
<td align="center" style="color:white; font-size: 15px; font-family:Tahoma"> <?=$pessoa["endereco"]?></td>
<td align="center" style="color:white; font-size: 15px; font-family:Tahoma">
<form align="center" action="alterar_pessoa.php" name="alterar" method="POST">
<input type="hidden" name="id" value=<?=$pessoa["id"]?>>
<input type="submit" class="btn editar cor" value="Editar" name="Editar" class="btn btn-default">
</form>
</td>
<td>
<form align="center" action="registra_pessoa.php" name="excluir" method="POST">
<input type="hidden" name="id" value=<?=$pessoa["id"]?>>
<input type="hidden" name="acao" value="excluir"/>
<input type="submit" class="btn editar excluir" onclick="msgSucesso()" value="Excluir" name="excluir" class="btn btn-default">
</form>
</td>
</tr>
</div>
<script>
function msgSucesso(){
alert('Pessoa excluida com sucesso');
}
</script>
<?php
}
}else{
echo('Ainda não existem clientes cadastrados');
}
?>
</table>
</div>
</body>
</html>
Registra_pessoa.php:
<?php
session_start();
require_once('db.class.php');
if(!$_SESSION['usuario']){
header('Location: index.php?erro=1');
}
if(isset($_POST['acao'])){
if($_POST['acao'] == "inserir"){
inserirPessoa();
}
if($_POST['acao'] == "alterar"){
alterarPessoas();
}
if($_POST['acao'] == "excluir"){
excluirPessoas();
}
if($_POST['acao'] == "filtrar"){
filtraPessoas();
}
}
function abrirBanco(){
$conexao = new mysqli("localhost", "root", "", "despesas");
return $conexao;
}
function valortotal(){
$grupo = selectContas();
foreach($grupo as $contas){
$valortotal += $contas["valor"];
}
}
function inserirPessoa(){
$nome = $_POST['nome'];
$datanascimento = $_POST['nascimento'];
$endereco = $_POST['endereco'];
$telefone = $_POST["telefone"];
$id = $_POST['id'];
$banco = abrirBanco();
$sql = "INSERT INTO pessoa(nome,nascimento,endereco,telefone) VALUES ('$nome', '$datanascimento', '$endereco', '$telefone')";
$banco->query($sql);
$banco->close();
header('Location: home.php');
}
function filtraPessoas(){
$grupo = '';
$banco = abrirBanco();
$teste = $_POST['nomefiltrar'];
$sql = "SELECT id, nome, DATE_FORMAT(nascimento, '%d/%m/%Y') AS data_formatada, endereco, telefone FROM pessoa WHERE nome LIKE '%$teste%' ";
$resultado = $banco->query($sql);
$banco->close();
while($row = mysqli_fetch_array($resultado)){
$grupo[] = $row;
}
return $grupo;
}
function selectIdPessoas($id){
$banco = abrirBanco();
$sql = "SELECT * FROM pessoa WHERE id = ".$id;
$resultado = $banco->query($sql);
$banco->close();
$pessoa = mysqli_fetch_assoc($resultado);
return $pessoa;
}
function alterarPessoas(){
$nome = $_POST['nome'];
$id = $_POST['id'];
$datanascimento = $_POST['nascimento'];
$endereco = $_POST['endereco'];
$telefone = $_POST['telefone'];
$id = $_POST['id'];
$banco = abrirBanco();
$sql = "UPDATE pessoa set nome = '$nome', nascimento = '$datanascimento', endereco = '$endereco', telefone = '$telefone' WHERE id= '$id' ";
$banco->query($sql);
$banco->close();
header('Location: consulta_clientes.php');
}
function excluirPessoas(){
$nome = $_POST['nome'];
$id = $_POST['id'];
$datanascimento = $_POST['nascimento'];
$endereco = $_POST['endereco'];
$telefone = $_POST['telefone'];
$id = $_POST['id'];
$banco = abrirBanco();
$sql = "DELETE FROM pessoa WHERE id= '$id' ";
$banco->query($sql);
$banco->close();
header('Location: consulta_clientes.php');
}
?>
pdf_clients.php:
<?php
include_once("registra_pessoa.php");
include("./MPDF57/mpdf.php");
$nome_filtrar = (isset($_POST['nomefiltrar'])) ? $_POST['nomefiltrar'] : "teste";
$pessoas = filtraPessoas();
$mpdf = new mPDF();
$mpdf->setDisplayMode("fullpage");
$mpdf->WriteHTML("<h1 align='center'>Relatório de Clientes</h1> <hr/>");
$html = "
<table class='tabela'>
<thread>
<tr>
<th>Nome</span></th>
<th>Data de nascimento</span></th>
<th>Telefone</th>
<th>Endereço</th>
</tr>
</thread>
<tbody>
";
foreach($pessoas as $pessoa){
$html = $html ." <tr>
<td align='center'> {$pessoa["nome"]} </td>
<td align='center'> {$pessoa["data_formatada"]} </td>
<td align='center'> {$pessoa["telefone"]} </td>
<td align='center'> {$pessoa["endereco"]} </td>
</tr>";
}
$html = $html ."
</tbody>
</table>
<h1>{$nome_filtrar}</h1>
";
$css = file_get_contents('pdf_estilo.css');
$mpdf->WriteHTML($css, 1);
$mpdf->WriteHTML($html);
$mpdf->Output();
exit();
?>
yes the test variable was not sent via $_POST, because the form is sent to query clients.php (soon it will enter Else) and its function that fills the post is in registra_pessoa.php. correct me if I’m wrong. If so I’ll create a solution answer
– Julio Henrique
Correct. I know it sounds ridiculous, but it would be like a form to send the data to two different pages?
– veroneseComS
You know ajax? da to do with it, when you write the name it sends this value to a page and returns this group. or you can do it without ajax but that’s the trick. Whatever you want?
– Julio Henrique
sends an example with ajax?
– veroneseComS
ok Leticia, I just didn’t understand one thing. This form will it consult clients based on that name you write? if yes then why does Voce want to filter first? or else this filter will give you a list of names that contain what you wrote, and then check the clients for that list? Are you using jquery?
– Julio Henrique
This form "filterClients" I made to filter a list of names that contains what to write in the "filtername" field, it sends to the same page "consult_clients.php", this page does the select: $group = filterPeople();
– veroneseComS