Within the while I created the delete button:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;
The action = "./delete"
I put it this way because I'm working on wordpress and the action
of this form is equal to action = "delete.php"
.
After deleting.php I have this code:
$id = $_POST['IdEstado'];
$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
When I click the delete button it does not delete anything in the database table.
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>