0
I want to press the DELETE button and delete X database data
this is my product type.php
<?php require("header.php"); ?>
<?php require("menu.php"); ?>
<?php
require ("model/tipo_itens.php");
$modTipoItens = new TipoItens();
$registros = $modTipoItens->getAll();
?>
<div class="container">
<center><h1>Categorias</h1></center>
<button type="button" class="btn btn-success" onclick="window.location.href='tipo_produto_novo.php'">Nova Categoria</button>
<table class="table table-striped">
<thead>
<tr>
<th>#</th> <th>Nome</th> <th>Descrição</th>
</tr>
</thead>
<tbody>
<?php foreach ($registros as $registro) { ?>
<tr>
<th scope="row"><?php echo $registro['id_tipo']; ?></th> <td><?php echo $registro['nome']; ?></td> <td><?php echo $registro['descricao']; ?></td>
<td>
<button type="button" onclick="editar(<?php echo $registro['id_tipo']; ?>)" class="btn btn-primary">Editar</button>
<button type="button" onclick="delete(<?php echo $registro['id_tipo']; ?>" class="btn btn-danger">Apagar</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script type="text/javascript">
function editar(id){
window.location.href="tipo_produto_novo.php?id="+id;
}
</script>
<?php require("footer.php"); ?>
When I click the DELETE button, I want to delete the item selected by the ID.
this is my entry type controller.php
<?php
require ("../model/tipo_itens.php");
call_user_func($_GET['acao']);
function inserir(){
$modTipoItens = new TipoItens();
$resultado = $modTipoItens->inserir($_POST);
header('Location: /exemplo/tipo_produto.php');
exit;
}
function editar(){
$modTipoItens = new TipoItens();
$resultado = $modTipoItens->editar($_POST);
header('Location: /exemplo/tipo_produto.php');
exit;
}
function delete(){
$modTipoItens = new TipoItens();
$resultado = $modTipoItens->delete($_POST);
header('Location: /exemplo/tipo_produto.php');
}
?>
and this is my delete function in the item type model.php
function delete($id){
$conexao = mysqli_connect('localhost','root', '', 'estoque');
$id = (int) $id;
$result = mysqli_query($conexao,"delete from tipo_itens where id_tipo= ".$id);
return $result;
}
I am unable to send the ID parameter when I click on the button and execute the delete function of my model/item type.php
Try it this way: <button type="button" onclick="edit('<?php echo $record['id_type']; ?>')" class="btn btn-Primary">Edit</button> <button type="button" onclick="delete('<?php echo $record['id_type']; ?>')" class="btn btn-Danger">Delete</button> Indicate which error appears if not.
– Rui Ferreira