Deleting a record in MySQL DB

0

Good afternoon. I need help with deleting a BD MySql record.

I have a DB that has a table called KEYS.

Ihaveapagecalledlist.php,thispagereceivesthevaluesfromthetableKEYS.OnthispageyouhavealinkcalledDELETEwhichwhenclickingthislinkleadstoapagecalledexclusion.php.

Thisexclusionpageuses$_GETtogetthecorrespondingcodeintheDBanddynamicallypopulatetheDeletion.phppage

Theproblem:WhenIclickedontheconfirmbuttonthedeletionwastodeletetherecordintheDBandreturntotheListing.phppagewiththechangepageupdatedwithouttherecordline.

IamnotabletodeletetherecordwhenIclickthebuttonitisgiving(errorindeletingtherecord).

IhavecheckedthecodeseveraltimesandamnotfindingtheerrorthatispreventingdeletionintheDBandtheupdate.

Phew!isthissorryforthelongtext,butjustsoIthinkI'mexplainingmyproblem.

Thisisthecode:IhadtoputtheHTMLprintofthecodebecauseitisbuggingwhenIampastingthecode.Thankyouverymuchforbeingabletohelp.

php//confirmarseàpáginafoichamadaapartirdoformuláriodeexclusãoif(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);

    
asked by anonymous 29.01.2018 / 20:15

1 answer

1

Remove the asterisk.

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

It will work!

    
29.01.2018 / 20:33