Confirm before deleting a record?

0

What I'm looking for is to confirm before doing the deletion.

This is my form.

  

removeClient.php

<!DOCTYPE html>
<html>
<head>
     <meta http-equiv="Content-type" content="text/html"; charset="utf-8">
     <title>Eliminar Clientes</title>
     <link rel="stylesheet" type="text/css" href="estilos.css">
         </style>
</head>
<body class="body">

        <form method="POST" action="eliminandoCliente.php" class="form">

        <h1>Eliminar Cliente</h1>
        <label>NIT del cliente a eliminar:</label>
        <input type="text" REQUIRED name="id" size="20" class="input">

        <input type="submit" value="Eliminar" name="B1" class="submit">     

        <input type="button" value="Volver de donde viniste!" onclick="location='http://localhost/Aeroasistencia/Administracion/edicionCliente.php'" class="submit" />

</body>
</html> 
  

removingClient.php

<?php
// Actualizamos en funcion del id que recibimos

$id = $_POST['id'];

$conexion =  mysqli_connect("localhost", "root","admin123","database");

    //$id_Funcionario = $_POST["id_Funcionario"];

$query = "DELETE FROM cliente where NIT = '".$id."'"; 
$result = mysqli_query($conexion,$query); 

if (!$result) {

           echo       
             '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://localhost/Aeroasistencia/Administracion/edicionCliente.php">
            <script>
                alert("El cliente NO  fue eliminado EXITOSAMENTE");
            </script>';

        }else{

            echo        
            '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://localhost/Aeroasistencia/Administracion/edicionCliente.php">
            <script>
                 alert("El cliente fue eliminada EXITOSAMENTE");
            </script>';

        }
?>
    
asked by Cristian Antonio Trujillo Gris 15.05.2018 в 15:40
source

1 answer

2

For that you should do a popup with javascript, so that before sending the form, it shows you this message. For example:

<!DOCTYPE html>
<html>
<head>
     <meta http-equiv="Content-type" content="text/html"; charset="utf-8">
     <title>Eliminar Clientes</title>
     <link rel="stylesheet" type="text/css" href="estilos.css">
</head>
<body class="body">

      <form method="POST" action="eliminandoCliente.php" class="form" id="miFormulario">

        <h1>Eliminar Cliente</h1>
        <label>NIT del cliente a eliminar:</label>
        <input type="text" REQUIRED name="id" size="20" class="input">

        <input type="submit" value="Eliminar" name="B1" class="submit">     

        <input type="button" value="Volver de donde viniste!" onclick="location='http://localhost/Aeroasistencia/Administracion/edicionCliente.php'" class="submit" />
      </form>
     <script type="text/javascript">
       (function() {
         var form = document.getElementById('miFormulario');
         form.addEventListener('submit', function(event) {
           // si es false entonces que no haga el submit
           if (!confirm('Realmente desea eliminar?')) {
             event.preventDefault();
           }
         }, false);
       })();
     </script>
</body>
</html>

I use the function confirm() of javascript that returns a Boolean value, true when it accepts.

    
answered by 15.05.2018 / 16:44
source