0
Script form (all_process.php):
<?php
require 'conexao.php';
$conexao = conexao::getInstance();
$acao = (isset($_POST['acao'])) ? $_POST['acao'] : '';
$proc_id = (isset($_POST['proc_id'])) ? $_POST['proc_id'] : '';
$numero = (isset($_POST['numero'])) ? $_POST['numero'] : '';
$assunto = (isset($_POST['assunto'])) ? $_POST['assunto'] : '';
$requerente = (isset($_POST['requerente'])) ? $_POST['requerente'] : '';
$status = (isset($_POST['status'])) ? $_POST['status'] : '';
$inf_id = (isset($_POST['inf_id'])) ? $_POST['inf_id'] : '';
$de_setor = (isset($_POST['de_setor'])) ? $_POST['de_setor'] : '';
$para_setor = (isset($_POST['para_setor'])) ? $_POST['para_setor'] : '';
$informe = (isset($_POST['informe'])) ? $_POST['informe'] : '';
$data = (isset($_POST['data'])) ? $_POST['data'] : '';
$informante = (isset($_POST['informante'])) ? $_POST['informante'] : '';
$processo_id = (isset($_POST['processo_id'])) ? $_POST['processo_id'] : '';
if ($acao == 'incluir'):
$processos = "INSERT INTO processos(proc_id, numero, assunto, requerente, status)
VALUES(:proc_id, :numero, :assunto, :requerente, :status)";
$stm = $conexao->prepare($processos);
$stm->bindValue(':proc_id', $proc_id);
$stm->bindValue(':numero', $numero);
$stm->bindValue(':assunto', $assunto);
$stm->bindValue(':requerente', $requerente);
$stm->bindValue(':status', $status);
$retorno = $stm->execute();
if ($stm->execute()){
$informes = "INSERT INTO informes(inf_id, de_setor, para_setor, informe, data, informante, processo_id)
VALUES (:inf_id, :de_setor, :para_setor, :informe, :data, :informante, :processo_id)";
$tsm = $conexao->prepare($informes);
$tsm->bindValue(':inf_id', $inf_id);
$tsm->bindValue(':de_setor', $de_setor);
$tsm->bindValue(':para_setor', $para_setor);
$tsm->bindValue(':informe', $informe);
$tsm->bindValue(':data', $data);
$tsm->bindValue(':informante', $informante);
$tsm->bindValue(':processo_id', $processo_id);
$lol = $tsm->execute();
if ($lol):
echo "<div class='center1' role='alert'>Processo inserido com sucesso, aguarde você está sendo redirecionado...</div> ";
echo "<div class='loader'</div>";
else:
echo "<div class='center1' role='alert'>Erro ao inserir processo, aguarde!</div>";
echo "<div class='loader'</div>";
endif;
echo "<meta http-equiv=refresh content='4;URL=listarprocessos.php'>";
}
endif;
Script listing (list of processes.php):
<?php
require_once ('restrito.php')
?>
<?php
require 'conexao.php';
$termo = (isset($_GET['termo'])) ? $_GET['termo'] : '';
if (empty($termo)):
$conexao = conexao::getInstance();
$sql = 'SELECT numero, assunto, requerente, status, de_setor, para_setor, informe, data, informante, setor FROM informes, processos, setores
WHERE processos.proc_id = informes.processo_id
GROUP BY informes.inf_id ASC;';
$stm = $conexao->prepare($sql);
$stm->execute();
$clientes = $stm->fetchAll(PDO::FETCH_OBJ);
else:
$conexao = conexao::getInstance();
$sql = 'SELECT numero, assunto, requerente, status, de_setor, para_setor, informe, data, informante, setor FROM informes, processos, setores WHERE assunto LIKE :assunto OR numero LIKE :numero OR requerente LIKE :requerente';
$stm = $conexao->prepare($sql);
$stm->bindValue(':assunto', $termo.'%');
$stm->bindValue(':numero', $termo.'%');
$stm->bindValue(':requerente', $termo.'%');
$stm->execute();
$clientes = $stm->fetchAll(PDO::FETCH_OBJ);
endif;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Listagem - Controle de Processos</title>
<link rel="stylesheet" type="text/css" href="css/xdxd.css">
<link rel="stylesheet" type="text/css" href="css/haha.scss">
<link rel="stylesheet" type="text/css" href="css/xdxd.mas.css">
<link rel="stylesheet" type="text/css" href="css/haha.mas.scss">
<link rel="stylesheet" type="text/css" href="css/site.css">
<link rel="stylesheet" type="text/css" href="css/tables.css">
<link rel="icon" href="imagens/pref.ico">
</head>
<body>
<div class="container">
<legend><h1 class="w3-center">Listagem de Processos</h1></legend>
<form action="" method="get" id='form-contato' class="form-horizontal col-md-10">
<label class="col-md-2 w3-text-black control-label" for="termo">Pesquisar</label>
<div class='col-md-7'>
<input type="text" class="form-control" id="termo" name="termo" placeholder="Informe o número ou nome do Processo"> <button type="submit" class="w3-button w3-black w3-right w3-display-right xdxd">Pesquisar</button>
</div><br></br>
<p> <a href='listarprocessos.php' class="w3-button w3-black xd">Ver Todos</a> </p>
<p> <a href='registrarprocesso.php' class="w3-button w3-gray xd">Registrar Processo</a> </p>
<p> <a href='index.php' class="w3-button w3-black xd">Ir para o Site</a> </p>
</form>
<div class='clearfix'></div>
<?php if(!empty($clientes)):?>
<?php foreach($clientes as $cliente):?>
<?php
if (empty($termo)):
?>
<table style='width:100%'>
<tr>
<th class='w3-text-black'>Número</th>
<td class='w3-text-black'><?=$cliente->numero?></td>
</tr>
<tr>
<th class='w3-text-black'>Assunto</th>
<td class='w3-text-black'><?=$cliente->assunto?></td>
</tr>
<tr>
<th class='w3-text-black'>Status</th>
<td class='w3-text-black'><?=$cliente->status?></td>
</tr>
<tr>
<th class="w3-text-black">Requerente</th>
<td class='w3-text-black'><?=$cliente->requerente?></td>
</tr>
</tr>
<?php
else:
?>
<table style='width:100%'>
<tr>
<tr>
<th class='w3-text-black'>Número</th>
<td class='w3-text-black'><?=$cliente->numero?></td>
</tr>
<tr>
<th class='w3-text-black'>Assunto</th>
<td class='w3-text-black'><?=$cliente->assunto?></td>
</tr>
<tr>
<th class="w3-text-black">Requerente</th>
<td class='w3-text-black'><?=$cliente->requerente?></td>
</tr>
<tr>
<th class='w3-text-black'>Status</th>
<td class='w3-text-black'><?=$cliente->status?></td>
</tr>
<tr>
<th class='w3-text-black'>Setor de</th>
<td class='w3-text-black'><?=$cliente->setor?></td>
</tr>
<tr>
<th class='w3-text-black'>Para setor de</th>
<td class='w3-text-black'><?=$cliente->setor?></td>
</tr>
<tr>
<th class='w3-text-black'>Informe de <?=$cliente->setor?></th>
<td class='w3-text-black'><?=$cliente->informe?></td>
</tr>
<tr>
<th class='w3-text-black'>Data</th>
<td class='w3-text-black'><?=$cliente->data?></td>
</tr>
<tr>
<th class='w3-text-black'>Informante</th>
<td class='w3-text-black'><?=$cliente->informante?></td>
</tr>
</tr>
<?php
endif;
?>
<BR></BR>
<BR></BR>
<tbody>
<?php endforeach;?>
</tbody>
</table>
<?php else: ?>
<h3 class="text-center text-primary">Não existem processos registrados!</h3>
<?php endif; ?>
</fieldset>
</div>
<script type="text/javascript" src="js/custom.js"></script>
</body>
</html>
When you check
if($stm->execute())
the recording method runs again. You need to make a query to check if the data was actually recorded and then use in its conditional structure or store a variable the boolean result of the run function.– Atila Silva
put the variable $return in if, saved only one data but the $informes were not entered. I believe he is not reading the $informes or the $tsm
– Bernardo Rodel
Run the function only here :
if ($stm->execute()){
– Atila Silva
but so it writes twice the data of the lawsuits. , what a boring business.
– Bernardo Rodel