I'm a beginner and I'm having a problem with a button (delete with modal). When clicking the button, the system should display the modal and if I click "yes", you should delete the registry.
I'm keeping my codes on a single page: "details.php".
Button code:
<form method="post" action="">
<div class="direita" style="padding-right:30px;">
<a href="#excluir" data-uk-modal >
<div class="btn_all2" type="submit" id='btnApagar' style="margin-left:15px; background-color:#ff0000;">
EXCLUIR </div> </a>
</form>
Mod code:
<div id="excluir" class="uk-modal" >
<div class="uk-modal-dialog">
<div class="uk-modal-header">Excluir</div>
Deseja mesmo excluir a tarefa?
<div class="uk-modal-footer uk-text-right">
<a class="uk-button" href="">Não</a>
<a class="uk-button uk-button-primary" type="submit" name="botaoConfirma" value="true" href="painel_constru.php?constru=tarefas">Sim</a>
</div>
</div>
Button triggered condition:
$codigo=$_GET["id"];
if (isset($_POST["btnApagar"])) {
if (isset($_POST["botaoConfirmar"])) {
$comandoExcluir = "DELETE FROM tbTarefa WHERE idTarefa =" .$codigo;
$resultado = $c ->criarConsulta($comandoExcluir);
if ($resultado) {
echo "Removido com sucesso";
} else{
echo "Não foi removido";
}
}
}
Clicking the button does not delete the record. I was seeing that this can be done in ajax, but I do not have much practice yet and I would also like to know if it is possible to make it work that way. Thanks in advance.
Method of creating the query:
public function criarConsulta ($sql)
{
$this->conectarBd();
$this->comandoSql = $sql;
// $result= mysqli_query($con,$comandoSql);
if ($this->result =mysqli_query($this->con,$this->comandoSql)) {
$this->desconectarBd();
return $this->result;
} else {
echo "Nao foi possivel realizar comando sql";
die();
$this->desconectarBd();
}
}