0
I am a beginner and I have a problem with a button (delete with modal). When clicking the button, the system should display the modal and if I click "yes", should delete the record.
I’m keeping my codes on one page only: "detailsTarefas.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>
Modal 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>
Condition triggered by the button:
$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";
        }
    }
}
By clicking the button the record is not deleted. I was seeing that this can be done in ajax, but I don’t 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();
     }
} 
Post the create codeConsult()
– Mauro Alexandre
<code>public Function createConsult($sql) { $this->conectarBd(); $this->commandSql=$sql; // $result= mysqli_query($con,$commandSql); if($this->result =mysqli_query($this->con,$this->commandSql)) { $this->disconnectBd(); Return $this->result; } Else { echo "Unable to perform sql command"; die(); $this->disconnectBd(); } } </code>
– Edmo Souza
Note: In addition to the problem presented, there is also risk of SQL Injection in your code. To avoid risk, treat data entry.
– Ivan Ferrer