Delete button does not work!

Asked

Viewed 60 times

-1

Good evening! I have a page excluirConta.php that is not functional, here is the code:

<?php
session_start();
require_once("../banco/conexao.php");

if (isset($_SESSION['id'])) {
    $id = $_SESSION['id'];
    $query = "DELETE * FROM usuario WHERE id = " . $_SESSION['id'];
    $result = mysqli_query($conexao, $query);

    if (!$result) {
        die("Falha ao excluir dados.");
    } else {
        echo "<script type='text/javascript'>window.alert('Usuário Excluído com Sucesso!');</script>";
        echo '<meta HTTP-EQUIV="Refresh" CONTENT="1; URL="../index.php">';
        exit;

        header("Location: ../index.php");
    }
}

And here’s the form I’m passing the variable in:

<form action="excluirConta.php?id=<?php echo $_SESSION['id']; ?>" method="POST">

              <label class="col-md-3 control-label"></label>
                 <div class="col-md-8">
                     <input class="btn btn-danger" type="submit" value="Excluir Conta"name="excluirUsuario" onclick="return confirm('Você está prestes a excluir a sua conta e todos os seus dados serão perdidos. Tem certeza?');" />
                 </div>
               </form>

When I click delete, the only thing that happens is that the page updates and the data appears in the URL, as if I was getting by GET, someone can help?

  • Please avoid long discussions in the comments; your talk was moved to the chat

  • I was hoping to pop up the option to move to the chat, but she didn’t show up. There is a possibility that I can move the conversation to the chat at any time during the conversation ?

1 answer

0


Follow the answer code:

<div class="col-md-8">

  <a href="excluirConta.php?id=<?php echo $_SESSION['id'];?>" class="btn btn-danger">Excluir Conta</a>

</div>

Filing cabinet: excluirConta.php

<?php

session_start();
require_once("../banco/conexao.php");

if (isset($_GET['id'])) 
{
    $id = $_GET['id'];
    $query = "DELETE FROM usuario WHERE id = $id";
    $result = mysqli_query($conexao, $query);

    if (!$result) {
        die("Falha ao excluir dados.");
    } else {

      $mensagem = 'Usuário Excluído com Sucesso';
      header("Location: ../index.php?msg=$mensagem");

    }
}?>

In the archive index php., insert the following code:

<?php 

if(isset($_GET['msg']))
{
    echo "<script>alert('" . $_GET['msg'] . "');</script>";
}

?>

Browser other questions tagged

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