I am doing a delete on my form manut_usuario
, below is my method to delete that is in class usuario.class.php
;
public function DelUsu($id){
try{
$delUsu = "DELETE FROM usuario WHERE idu_usujport = :id ";
$delUsu = $this->con->Connect()->prepare($delUsu);
$delUsu->bindValue(':id', $id, PDO::PARAM_INT );
$delUsu->execute();
$delUsu->fetch(PDO::FETCH_OBJ);
return $delUsu;
echo 'deletado';
}
catch(PDOException $erro_5){
echo 'erro'.$erro_5->getMessage();
}
}//Metodo Delete dados.
In my form below is the way I delete data by going to method DelUsu
<?php //crio um array para recuperar os dados e mostrar no formulario.
$objeto = new Usuario();
$usuario = $objeto->LerDadosUsu();
foreach($usuario as $usuario):
?>
<tr>
<td><?php print $usuario['nom_usujauport'] ?></td>
<td><?php print $usuario['ema_usujauport'] ?></td>
<td><?php print $usuario['sen_usujauport'] ?></td>
<!--FINAL DO ARRAY(RECUPERANDO SEM ERROS)-->
<!--DELETAR-->
<?php
$usuario = new Usuario();
$id=""; //zero a variável ID para pegar sempre a selecionada pelo administrador
if(isset($_POST['excl_usu'])){
$usuario->DelUsu($id);
echo "Excluido";
}else{
echo "Não Excluido!!";
}
?>
When executing the program and doing the delete by clicking on the button <"excl_usu">
gives the error below
errorSQLSTATE [HY000]: General errorExcluded
Below is my form where I end up as foreach
.
<?php
$objeto = new Usuario();
$usuario = $objeto->LerDadosUsu();
foreach($usuario as $usuario):
?>
<tr>
<td><?php print $usuario['nom_usujauport'] ?></td>
<td><?php print $usuario['ema_usujauport'] ?></td>
<td><?php print $usuario['sen_usujauport'] ?></td>
<!--FUNÇÕES PARA CARREGAR DADOS NAS ALTERAÇÕES-->
<!--DELETAR-->
<?php
$usuario = new Usuario();
$id="";
if(isset($_POST['excl_usu'])){
$usuario->DelUsu($id);
echo "Excluido";
}else{
echo "Não Excluido!!";
}
?>
<!--FINAL DELETAR-->
<!--ALTERAR-->
<?php
?>
<!--FINAL ALTERAR-->
<td><p data-toggle="tooltip" title="Edit">
<button type="submit" class="btn btn-primary" data-title="Editar" data-toggle="modal" data-target="#edit" nome="alterar" id="alterar"><i class="fa fa-edit"> Alterar</i></button></p></td>
<td><data-toggle="tooltip" title="Delete">
<button type="submit" class="btn btn-primary " nome="excl_usu" id="excl_usu"><i class="fa fa-trash-o"> Excluir</i></button></p></td>
</tr>
<tr>
</tbody>
</table>
<?php
endforeach;
?>
</form>
<div class="clearfix" align="center"></div>
<ul class="pagination pull-right">
<li class="disabled"><a href="#"><span class="glyphicon glyphicon-chevron-left"></span></a></li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#"><span class="glyphicon glyphicon-chevron-right"></span></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<form action="" id="frm_atu_usu" name="frm_atu_usu" method="POST" >
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">Editar Usuario</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input class="form-control " type="text" placeholder="Nome:">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="Email:">
</div>
<div class="form-group">
<textarea rows="2" class="form-control" placeholder="Senha:"></textarea>
</div>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-sucessful btn-lg"><span class="glyphicon glyphicon-ok-sign"></span> Atualizar</button>
</div></form>
</div>
</div>
</div>