0
I made a form, where when the user clicks the delete button, the value entered in the imput 'id' is deleted from the database. Thanks in advance for your help.
Follow my form.
<form name="Form_CRUD" method="post" action="consulta.php" >
<div class="row">
<div class="col-6">
<div class="form-group">
<input type="hidden" id="id_input" class="form-control" name="id">
<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" name="Add" class="btn btn-primary">Adicionar</button>
<button type="submit" name="Upd" class="btn btn-primary">Alterar</button>
<button type="submit" name="Del" class="btn btn-primary">Excluir</button>
</div>
</div>
</form>
<?php
$validarenvio = isset($_GET['s']) ? $_GET['s'] : '';
if ($validarenvio == '1') :
?>
<div class=" alert alert-success" role="alert">
<strong>Sucesso!</strong>
Cadastro realizado com sucesso
</div>
<?php endif; ?>
<?php
if($validarenvio == '2'):
?>
<div class=" alert alert-success" role="alert">
<strong>Sucesso!</strong>
Alterado com sucesso!
</div>
<?php endif; ?>
<?php
if($validarenvio == '3'):
?>
<div class=" alert alert-success" role="alert">
<strong>Sucesso!</strong>
Excluido com sucesso!
</div>
<?php endif; ?>
<?php
if($validarenvio == '0'):
?>
<div class=" alert alert-danger" role="alert">
<strong>Erro!</strong>
Erro de envio verifique!
</div>
<?php endif; ?>
Follow my.php query:
<?php
require_once ('classes/conecta.php');
$idCli = trim($_POST['id']);
$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();
$erro = 0;
$up = "UPDATE clientes_cli";
$up .= " SET nome_cli = '$nomeCli', sobrenome_cli = '$sobrenomeCli'";
$up .= "WHERE cod_cli = $idCli";
$del = "DELETE From clientes_cli";
$del .= "WHERE cod_cli = $idCli";
if (isset($_POST['Add'])){
header('Location: index.php?s=1');
$inserir_dados = $Obj_Conexao->Consulta($insert);
exit;
} else if (isset($_POST['Upd'])) {
header('Location: index.php?s=2');
$alterar_dados = $Obj_Conexao->Consulta($up);
exit;
} else if (isset($_POST['Del'])){
header('Location: index.php?s=3');
$Deletar_dados = $Obj_Conexao->Consulta($del);
exit;
} else {
header('Location: index.php?s=0');
exit;
}
?>
Gabriel, yes my cod_cli is my PK yes.
– Moises Moraes
I made the modification of your item three and it did not function!
– Moises Moraes
The message to the user is responding comfort the programmed. But in the database no action occurs.
– Moises Moraes