delete files from the table

0

I'm trying to delete an item from the table, but when I click it it does not delete.  It recognizes the id and everything else, but when I update the item it has not been deleted.

<?php
     include_once("conexao.php");
    if(! $conn ) {
      die('Could not connect: ' . mysqli_error());
   }
   echo 'conexão feita com sucesso<br>';
   $sql = 'DELETE FROM fornec WHERE id = "$row"';

   if (mysqli_query($conn, $sql)) {
      echo "Deletado com sucesso";
   } else {
      echo "Error: " . mysqli_error($conn);
   }
   mysqli_close($conn);
?>

It's like this. As I mentioned before, it recognizes the id that I clicked, but does not delete.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
        $titulo = "Controle &raquo; Listar Material";
        require_once ("includes/header.php"); 
    ?>
</head>
<title> </title>
<style>
table {
    border-collapse: collapse;
    width: 100%;
}

th, td {
    text-align: left;
    padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
    background-color: #4CAF50;
    color: white;
}
</style>
</head>
<body>
                <?php
    require_once('includes/testes.php');
    ?>


<?php
// Conexão ao banco
//require_once('conexao.php');
?>
<div id="principal">
                <form action="<?php $_SERVER['PHP_SELF']?>" method="post">
                    <fieldset>


<?php
require_once('conexao.php');


echo"<table width='100%' border='1'>";

echo '<table>';
echo '<tr>';
echo'<td>id</td>';
echo'<td>NOME</td>';
echo'<td>TELEFONE</td>';
echo'<td>Editar</td>';
echo'<td>Excluir</td>';
echo '</tr>';
$res = mysqli_query($conn, "SELECT * FROM fornec");


while($row = mysqli_fetch_array($res)){

echo '<tr>';
echo '<td>'.$row["id"].'</td>';
echo '<td>'.$row["NOME"].'</td>';
echo '<td>'.$row["FONE_2"].'</td>';
//echo '<td><a href=\"editar_fornec.php?id'.$row["id"].' \">✍</a>';
echo '<td><a href="editar_fornec.php?id='.$row['id'].'">✍</a>
      <td><a href="deleta2.php?id='.$row['id'].'">✖</a>
      </tr>';
}
echo '</table>';                

?>
<!-- a href ="listar_fornec.php?delete=<?php //echo $id; ?>">Delete</a>
-->

    </fieldset>             
        </form>
            </div> <!-- Fim da div#principal -->
</body>

</html>
    
asked by anonymous 12.04.2017 / 14:49

1 answer

0

Change your code to debug.

If you have returned code 23000 or integrity message may be foreign key. Take a look also at the permissions you have to manipulate the bank.

$sql = 'DELETE FROM fornec WHERE id = "$row"'; 
$result = mysqli_query($conn, $sql);
echo $result; //debug

if ($result)) { echo "Deletado com sucesso"; } else { echo "Error: " . mysqli_error($conn); } mysqli_close($conn); ?>
    
12.04.2017 / 14:58