0
I’m trying to insert a message into the library when it makes a record. But when sending is done the message does not appear for use. Thanks for the help!
Follow my form
<form name="Form_CRUD" method="post" action="consulta.php" >
<div class="row">
<div class="col-6">
<div class="form-group">
<label>Nome</label>
<input type="text" id="nome_input" class="form-control" name="nome">
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="form-group">
<label>Sobrenome</label>
<input type="text" class="form-control" id="sobrenome_input" name="sobrenome">
</div>
<button type="submit" class="btn btn-primary">Adicionar</button>
<button type="submit" class="btn btn-primary">Alterar</button>
<button type="submit" class="btn btn-primary">Excluir</button>
</div>
</div>
</form>
<?php
$validarenvio = isset($_GET['s=1'])?$_GET['s=1']:'';
if ($validarenvio):
?>
<div class=" alert alert-success" role="alert">
<strong>Sucesso!</strong>
Cadastro realizado com sucesso
</div>
<?php endif; ?>
<?php
$validarenvio = isset($_GET['s=0'])?$_GET['s=0']:'';
if ($validarenvio):
?>
<div class=" alert alert-danger" role="alert">
<strong>erro!</strong>
Erro de envio verifique!
</div>
<?php endif; ?>
Follow my query . php:
<?php
require_once ('classes/conecta.php');
$nomeCli = trim($_POST['nome']);
$sobrenomeCli = trim($_POST['sobrenome']);
$insert = "INSERT INTO clientes_cli";
$insert .= " (nome_cli, sobrenome_cli)";
$insert .= "VALUES ('$nomeCli', '$sobrenomeCli')";
$Obj_Conexao = new CONEXAO();
$inserir_dados = $Obj_Conexao->Consulta($insert);
$erro = 0;
if($inserir_dados == false){
header('Location: index.php?s=0');
} else{
header('Location: index.php?s=1');
}
?>
Funfou but in parts! Because the error messages is appearing and should be hidden. They should appear when there is a submission! As I do now?
– Moises Moraes
I edited the answer
– Costamilam
William, Why in your logic the if has no endif?
– Moises Moraes
William. The message still continues.
– Moises Moraes
I prefer the syntax with brackets
{ }
to delimit the part within theif
/else
– Costamilam