PHP page connects to the database, loads but does not delete

Asked

Viewed 24 times

0

Could you help me identify what’s wrong with this code?

<?php
     include ("conexao.php");?>
     <?php
     $id = isset ($_POST['id']) ? $_POST['id']:'';
     $sql= "DELETE FROM `guaxinim` WHERE `guaxinim`.`id`=".$id;
     $result = mysqli_query($conn, $sql);
     if($result)
         die ("O registro foi excluído.");
      else
         echo "Infelizmente não foi possível excluir.";

    header('Location: cadastros.php');
?>

because the page loads when I take the "header" appears that it worked and does not appear to be an error, but when I check the database the data is still there.

1 answer

1


How are you working with anchor (links with parameters) and not with form (<form>), you must use $_GET instead of $_POST, for example:

$id = isset ($_GET['id']) ? $_GET['id'] : '';

Do not forget to remove the echo, otherwise header won’t work.

  • Sensational guy was even worth for the speed of response and that was exactly what was happening went all right now vlw brother!!!

Browser other questions tagged

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