My delete is deleting the table data but not redirecting to the page I want

Asked

Viewed 29 times

0

*IN CASE IT DISPLAYS "echo "error while deleting";" even the data has been deleted from the table. Please help me!

Page of functions:

 require 'conexao.php';

    function apagar($cod_pedido) {
        $link = conexao();
        $query = "delete from pedido_oracao where cod_pedido = '{$cod_pedido}'";
        mysqli_query($link, $query);
      } 

Page delete requests.php:

<?php
require 'funcoes.php';

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    $cod_pedido = $_GET['cod_pedido'];

    if (apagar($cod_pedido)) {
        header('Location: index.html');
        exit;
    } else {
        echo "erro ao apagar";
    }
}

Where I’m pulling in html:

<?php foreach ($dados as $lista) { ?>
....
....
....
....
<div class="cell cell2" data-title="Excluir">
                                <a class="excluir" href="apagarPedidos.php?cod_pedido=<?= $lista['cod_pedido'] ?>"><i class="fas fa-trash-alt"></i></a>
                            </div>
    </div>
                    <?php } ?>

2 answers

0

failed to return the status of mysqli_query...

function apagar($cod_pedido) {
    $link = conexao();
    $query = "delete from pedido_oracao where cod_pedido = '{$cod_pedido}'";
    return mysqli_query($link, $query);
} 
  • It worked out! THANK YOU!

0

Try this as an alternative.

function apagar($cod_pedido) {
    $link = conexao();
    $query = "delete from pedido_oracao where cod_pedido = '{$cod_pedido}'";
mysqli_query($link, $query) or die ("Erro");
} 
  • I had dodged Return. Obg ai :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.