I can not remove an item from the database

Posted on

Question :

I’m trying to remove an item from the database, but it is not removing it.

        <form action="removelicita.php" method="post">
            <input type="hidden" name="id" value="<?=$licitacao['id']?>">
            <button type="button" class="btn btn-danger">Remover</button>
        </form>

Above the code snippet where I call the delete action.
Below the exclusion code:

<?php

require_once("conexao.php");

$id = $_POST["id"];

$query = "delete from insereLicitacao where id = $id";

if(mysqli_query($conexao,$query)){
    header("Location: listalicitacao.php");
    die();
} else {
    echo "Erro ao remover licitação";
}

    

Answer :

Change the type attribute of the button tag to submit the form

<button type="submit" class="btn btn-danger">Remover</button>

Reference:

link

    

Leave a Reply

Your email address will not be published. Required fields are marked *