Help with deleting record

Asked

Viewed 38 times

0

I have my employee delete but gives these mistakes:

"Undefined index: id in C: wamp www Sitephp base excluirFunctioning.php on line 6"

"PDO::exec() expects Parameter 1 to be string, Object Given in C: wamp www Sitephp base excluirFunctional.php on line 8".

Follows my code:

require_once '../base/conexao.php';
$id = $_GET['id'];
$delete = $PDO->query("DELETE  FROM funcionario WHERE id = '$id' ");
$PDO->exec($delete);
if ($id){
    echo "<script>alert('Registro de Funcionario deletado');location.href = 'listarFuncionario.php';  </script>";
}else{
    echo "<script>alert('Ocorreu um erro no processo');location.href = 'listarFuncionario.php';  </script>";
}

function excluir(id){
    if(confirm("Deseja excluir o registro?")){
        location.href = 'excluirFuncionario.php';
        
    }
}
<?php while($funcionario = $rs->fetch(PDO::FETCH_ASSOC)) { ?>
    <tr>
    <td align="center"><a href="excluirFuncionario.php" onkeyup="excluir(id)" onclick="excluir(<?php echo $funcionario['id'];?>)"><img src="../imagens/delete.png"></a></td>
         </tr>
         <?php }?>
</tbody>

  • From what I understand, there is no index id inside the $_GET, check if you are passing correctly!

  • I’m seeing if it’s a connection problem, because it’s not really looking for the ID

1 answer

1


You are not passing the ID in the URL... Try this way:

function excluir(id){
    if(confirm("Deseja excluir o registro?")){
        location.href = 'excluirFuncionario.php?id=' + id;

    }
}

<?php while($funcionario = $rs->fetch(PDO::FETCH_ASSOC)) { ?>
    <tr>
    <td align="center"><a href="#" onclick="excluir(<?php echo $funcionario['id'];?>)"><img src="../imagens/delete.png"></a></td>
         </tr>
         <?php }?>
</tbody>
  • Warning: PDO::exec() expects Parameter 1 to be string, Object Given in C: wamp www Sitephp base excluirFunctioning.php on line 10

  • Notice: Undefined index: id in C: wamp www Sitephp base excluirFunctioning.php on line 7

  • Presents these errors

  • @Ruanrodrigues changes the <a href=.... also!

  • 1

    You helped me a lot, thank you! Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.