Delete Registry in BD Mysql

Asked

Viewed 255 times

0

Good afternoon. I need help deleting a Mysql BD record.

I have a comic book that has a table called KEYS. inserir a descrição da imagem aqui

I have a page called listing.php, this page gets the table values KEYS. On this page is a link called DELETE which when clicking this link leads to a page called exclusion.php.

This exclusion page uses $_GET to pick up the corresponding code in the BD and dynamically fill in the Delete.php page

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

The problem: When I clicked the delete button it was to delete the registration in the BD and go back to the Listing.php page with the updated change page without the registration line.

I am unable to delete the record when I click on the button is giving (error in deleting the record).

I checked the code several times and am not finding the error that is preventing deletion in BD and update.

Phew! is this sorry for the long text, but just so I think I’m explaining my problem.

This is the code: I had to print the HTML of the code because it’s bugging when I’m pasting the code. I really appreciate anyone who can help.

php
//confirmar se à página foi chamada a partir do formulário de exclusão
if(isset($_POST["nomecolaborador"])){
    $chID = $_POST["IDchaves"];

    $exclusao = "DELETE * FROM chaves ";
    $exclusao .= "WHERE IDchaves = {$chID} ";

    $con_exclusao = mysqli_query($conexao,$exclusao);
    if(!$con_exclusao){
        die("Erro na exclusão do registro");
    }else{
        header("location:listagem.php");
    }
}

?php
  //consulta a tabela chaves
  $cha = "SELECT * FROM chaves ";
  if(isset($_GET["codigo"]) ){
    $id = $_GET["codigo"];
    $cha .="WHERE IDchaves = {$id} ";
 }

  $cons_chaves = mysqli_query($conexao,$cha);
  if(!$cons_chaves){
      die("Erro na consulta");
  }
  $info_chaves = mysqli_fetch_assoc($cons_chaves);

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

1 answer

1


Remove the asterisk.

$exclusao = "DELETE FROM chaves ";
$exclusao .= "WHERE IDchaves = {$chID} ";

Will work!

  • Hello Julio, man thanks even for the help, we were so blind looking at another problem that the solution may be in front of us. Thanks even!!

  • There worked your suggestion.

  • Unfortunately this happens, we spend hours and hours looking for a complex problem and then discover that it is simple. :)

  • Super true, sometimes we look for hair in egg. Strong hug! :)

Browser other questions tagged

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