How to implement a confirmation before executing an UPDATE

0

I have the following code:

    //APROBAR PAGOS MENSUALIDAD
 function aprobar_pago_mes() {
     global $db;
    $idusuario = ($_GET['id']);
    $sql = "UPDATE pagos SET
            status_pago = 'APROBADO'
            WHERE id = '$idusuario'";

if (mysqli_query($db, $sql)) {
    $_SESSION['pago_mensualidad']  = "Se ha Actualizado el usuario de manera correcta..!!";

 } else {
    echo "Error updating record: " . mysqli_error($db);
    mysqli_close($db);
 } }

Like this one it works perfectly, but I would like to know if it is possible to implement in that code a modal or a confirmation button before executing the UPDATE. I'm using Bootstrap 4.

In the PHP where the EDITAR button is, I tried the following:

      echo '<script language="javascript">
      function msg(){
        actualizar=confirm("¿Seguro que Desea Aprobar este pago?");
        if (actualizar)
   //Redireccionamos si das a aceptar
     window.location.href="mensualidades.php?id=';
     echo $rowid;
     echo '&user=';
     echo $rowUser;
     echo '"//página web a la que te redirecciona si confirmas la eliminación
else
  //Y aquí pon cualquier cosa que quieras que salga si le diste al boton de cancelar
    alert("No se Aprobo este pago")
      }
      </script>';
      $link_aprobar_mes = '<form autocomplete="off" class="was-validated" method="post" action= "mensualidades.php?id='.$rowid.'&user='.$rowUser.'"><button onclick="msg()" type="submit" class="btn btn-primary" name="aprobar_pago_btn">Aprobar</button> </form>';
echo '<tr>';
echo '<td>'.$rowid.'</td>
       <td>'.$rowUser.'</td>
       <td>'.$fecha_pago .'</td>
       <td>'.$rowmes['monto'].' BsS / '.$rowmes['mes_de_pago']. '</td>
       <td>'.$rowmes['nro_transf'] . ' / '.$rowmes['ci_nro_cuenta'].'</td>
       <td>'.$rowmes['banco_origen'].' / '.$rowmes['banco_destino'] .'</td>
       <td>'.$link_aprobar_mes .'</td>
      </tr>';

But so the user cancels the action of confirm() the php script runs in the same way and performs the Update and sends mail etc etc ..!

    
asked by Jose M Herrera V 18.09.2018 в 21:36
source

0 answers