Modificar Y Eliminar Registros Con Ventana Modal

yoclens Seguir

Gamma
Diseñador
Verificación en dos pasos desactivada
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
24 Sep 2016
Mensajes
160
Hola amigos actualmente tengo este problema estoy tratando de modificar y eliminar registros por medio de ventana modal de materialize.css, pero siempre me carga el primer registro que se muestra en mi tabla, me explico bien si en mi bd tengo dos registros:

id nombre
1 masculino
2 femenino


cuando le doy modificar o eliminar al segundo registros siempre me carga el primer registro.

anexo el código que tengo actualmente.


anadir_estado_civil.php


<table>
<thead>
<tr>
<th>N°</th>
<th>ID-BD</th>
<th>ESTADO CIVIL</th>
<th>ACCIONES</th>
</tr>
</thead>



<?php
$consulta = $DB_con->query("SELECT * FROM estado_civil ORDER BY id_estado_civil;");
if($consulta->rowCount() > 0){
$i=1;
?>

<?php

while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {

echo "
<tbody id='tabla'>
<tr>
<td>$i</td>";?>
<td><?php echo $linea['id_estado_civil']; ?></td>
<td><?php echo $linea['estado_civil']; ?></td>

<td>


<a href="#modificar_id_estado_civil=<?php echo ($linea['id_estado_civil']); ?>">
<button data-target="modal2" class='btn modal-trigger btn waves-effect waves-light blue' >
MODIFICAR</button></a>


<a href="#eliminar_id_estado_civil=<?php echo ($linea['id_estado_civil']); ?>">
<button data-target="modal3" class='btn modal-trigger btn waves-effect waves-light red' >
ELIMINAR</button></a>





</td>
<!-- ventana modal-->
<?php
include "ventana_modal_eliminar.php";
include "ventana_modal_modificar.php";
?>
<!-- fin ventana modal-->
</tr>
</tbody>

<?php

$i++;
}
}

else
echo "<div class='col s12 card-panel yellow darken-2 center'>
<h5 class='black-text text-darken-2 center CONDENSED LIGHT5'>
¡ Advertencia: No se ha encontrado ningún registro !
</h5>
</div>";
echo "</table>";
?>

ventana_modal_eliminar.php

<!-- ELIMINAR REGISTRO CON VENTANA MODAL -->
<div class="modal" id="modal3">
<div class="modal-content">
<h4>Eliminar Registro</h4>

<br>
¿Esta seguro de Borrar el registro?

<div class="row">
<div class="input-field col s12">


<?php echo $linea['id_estado_civil'].' '.$linea['estado_civil']; ?>

</div>
</div>

</div>


<div class="modal-footer">

<button class="modal-close btn waves-effect waves-light grey">CANCELAR</button>

<a href="config_eliminar_estado_civil.php?id_estado_civil=<?php print($linea['id_estado_civil']); ?>">
<button class="modal-close btn waves-effect waves-light red" type="submit" name="eliminar">ELIMINAR</button></a>

</div>
</div>
<!-- FIN ELIMINAR REGISTRO CON VENTANA MODAL -->


gracias de ante mano.
 

pmike

Gamma
Verificación en dos pasos desactivada
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
26 Feb 2012
Mensajes
368
Te falta por mostrar más codigo.
Si intentas modificar o eliminar tendras que tener los archivo javascript o PHP que se halle las instrucciones:
UPDATE y DELETE

Supongo que seran
  • ventana_modal_eliminar.php
  • ventana_modal_modificar.php

Tendras que mirar estos archivos para ver si realmente hacen esta rutina.
 

fmogro

Zeta
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Verificado por Binance
Desde
21 Mar 2014
Mensajes
1.611
Al crear un post tienes la opción de CODE.

Ponlo en un code para hacerlo más legible y ver si te puedo ayudar
 

yoclens

Gamma
Diseñador
Verificación en dos pasos desactivada
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Desde
24 Sep 2016
Mensajes
160
Al crear un post tienes la opción de CODE.

Ponlo en un code para hacerlo más legible y ver si te puedo ayudar
pagina para consultar registros, modificar y eliminar

anadir_estado_estado_civil.php


PHP:
<!-- la session-->
<?php
 
    session_start();
    if(!isset($_SESSION['id_nivel']))
      {
  
        header('Location: ../index.php?Error=Acceso denegado');
echo "<script>alert('Disculpe Acceso registringido, Usuario no Autorizado')</script>";

        exit();
      }
  ?>

<!-- fin de la session-->


<!-- conexion y errores-->
<?php
error_reporting( ~E_NOTICE );
include "../conexion/conexion.php";
//$crud = new crud($DB_con);
?>

<!-- fin conexion y errores-->

<!DOCTYPE html>
<html lang="es">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>SIGEU</title>
  <link rel="icon" href="mi favicon/sav1.png">
  <!--Import Google Icon Font-->
      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <!--Import materialize.css-->
      <link type="text/css" rel="stylesheet" href="../css/materialize.min.css"  media="screen,projection"/>

      <link rel="stylesheet" href="../css/dark.css">
      <!--Let browser know website is optimized for mobile-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

</head>

<body>

<!-- menu-->
<?php
include 'menu.php';
?>
<!-- fin menu-->

                  <br>
                         <br>


<!-- consultar registros -->
<div class="container">

<!-- boton para llamar a la ventana modal, excel y pdf-->
<a class="waves-effect waves-light btn modal-trigger" href="#modal1">
<i class="material-icons left">add</i>Añadir Registros</a>
<!-- fin boton para llamar a la ventana modal -->


<a class="waves-effect waves-light btn green"><i class="material-icons left">cloud</i>GENERAR EXCEL</a>

<a class="waves-effect waves-light btn red accent-4"><i class="material-icons left">picture_as_pdf</i>GENERAR PDF</a>

<!-- fin boton para llamar a la ventana modal, excel y pdf-->


    <div class="row">
       <div class="card cyan darken-3">
              <div class="card-tabs">
                <ul class="tabs tabs-fixed-width tabs-transparent">
                  <li class="tab"><a class="active">Listado General Tipos de Estado Civil</a></li>
                </ul>
              </div>

                     <div class="card-content white">
                     <div id="test1" class="center-align light">

<div class="row">
<input id="buscador" placeholder="FILTRAR REGISTROS">

            
</div>

<table>
        <thead>
          <tr>
              <th>N°</th>
              <th>ID-BD</th>
              <th>ESTADO CIVIL</th>
              <th>ACCIONES</th>
          </tr>
        </thead>



<?php
$consulta = $DB_con->query("SELECT * FROM estado_civil ORDER BY id_estado_civil;");
if($consulta->rowCount() > 0){
$i=1;
 ?>

<?php

while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {

echo "
        <tbody id='tabla'>
          <tr>
            <td>$i</td>";?>
            <td><?php echo $linea['id_estado_civil']; ?></td>
            <td><?php echo $linea['estado_civil']; ?></td>
          
<td>


<a href="#modificar_<?php echo $linea['id_estado_civil']; ?>">
<button data-target="modal2" class='btn modal-trigger btn waves-effect waves-light blue' >
MODIFICAR</button></a>


<a href="#eliminar_<?php echo $linea['id_estado_civil']; ?>">
<button data-target="modal3" class='btn modal-trigger btn waves-effect waves-light red' >
ELIMINAR</button></a>

</td>
<!-- ventana modal-->
<?php
include "ventana_modal_eliminar.php";
include "ventana_modal_modificar.php";
?>
<!-- fin ventana modal-->
</tr>
</tbody>

<?php

$i++;
}
}

else
echo "<div class='col s12 card-panel yellow darken-2 center'>
<h5 class='black-text text-darken-2 center CONDENSED LIGHT5'>
¡ Advertencia: No se ha encontrado ningún registro !
</h5>
</div>";
echo "</table>";
?>


<?php
$consulta = $DB_con->query("SELECT * FROM estado_civil");
$consulta->execute();
$estado_civil = $consulta->rowCount();
?>
<h6 class="right-align black-text"><?php print("TOTAL REGISTROS EXISTENTES:
<span class='red-text text-darken-2'><b>$estado_civil\n</b></span>"); ?></h6>



                </div>
            </div>

<!--  fin Pie de pagina-->
            <div class="col s12 center-align">
                  <label class="white-text">SISTEMA
                    <br>
                    <b>2022</b>
                  </label>
           </div>
<!--  fin Pie de pagina-->
              </div> 
        </div>
</div>

 <!--Import jQuery before materialize.js-->
     <script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>

 <!--JavaScript at end of body for optimized loading-->
      <script type="text/javascript" src="../js/materialize.min.js"></script>

<!--  Scripts-->


<!-- VALIDACION -->
  <?php
    if (isset($errMSG)) {
    ?>
        <script>
            var toastHTML = '<?php echo $errMSG; ?>';

            M.toast({
                html: toastHTML
            });
        </script>
    <?php
    } else if (isset($successMSG)) {
    ?>
        <script>
            var toastHTML = '<?php echo $successMSG; ?>';

            M.toast({
                html: toastHTML
            });
        </script>
          <?php
    }
    ?>
<!-- FIN VALIDACION -->


<script>
   $(document).ready(function() {
    $(".dropdown-trigger").dropdown();
    $(".button-collapse").sideNav();
  });
  </script>

<script>
   $(document).ready(function() {
    $(".modal").modal();
  });
  </script>



<!-- FILTRO DE TABLA-->
<script>
   $("#buscador").keyup(function () {
    //split the current value of searchInput
    var data = this.value.split(" ");
    //create a jquery object of the rows
    var jo = $("#tabla").find("tr");
    if (this.value == "") {
        jo.show();
        return;
    }
    //hide all the rows
    jo.hide();

    //Recusively filter the jquery object to get results.
    jo.filter(function (i, v) {
        var $t = $(this);
        for (var d = 0; d < data.length; ++d) {
            if ($t.is(":contains('" + data[d] + "')")) {
                return true;
            }
        }
        return false;
    })
    //show the rows that match.
    .show();
}).focus(function () {
    this.value = "";
    $(this).css({
        "color": "black"
    });
    $(this).unbind('focus');
}).css({
    "color": "#C0C0C0"
});
  </script>
<!-- FIN FILTRO DE TABLA-->


<!-- CONFIGURACION AGREGAR REGISTROS-->
<?php
include "config_agregar_estado_civil.php";
?>
<!-- FIN CONFIGURACION AGREGAR REGISTROS-->

<!-- ANADIR REGISTRO CON VENTANA MODAL -->
  <div id="modal1" class="modal">
    <div class="modal-content">
      <h4>Agregar Registro</h4>

        <form class="col s12" action="anadir_estado_civil.php" name="frmContacto" method="POST">

             <br>

<div class="row">
            <div class="input-field col s12">
            <input id='estado_civil' class="black-text" type="text" name="estado_civil" autocomplete="off" title="Se necesito el nombre, Este Campo solo Acepta Letras!"  required/>
            <label for="password">Estado Civil</label>
            </div>
</div>

    

    </div>


 <div class="modal-footer">

    <a href="#!" class="modal-close waves-effect waves-light grey btn-flat keychainify-checked">Cancelar</a>

    <button class="btn waves-effect waves-light teal" type="submit" name="agregar">Agregar</button>
</form>

    </div>
  </div>
<!-- FIN ANADIR REGISTRO CON VENTANA MODAL -->

</body>
</html>


ventana modal para eliminar registros

ventana_modal_eliminar.php


PHP:
<!-- ELIMINAR REGISTRO CON VENTANA MODAL -->
        <div class="modal" id="modal3" data-id="eliminar_<?php echo $linea['id_estado_civil']; ?>">



                <div class="modal-content">
                        <h4>Eliminar Registro</h4>

                                                    <br>
                                                    ¿Esta seguro de Borrar el registro?

<div class="row">
                                                <div class="input-field col s12">
                                                
                                                
                                                    <?php echo $linea['id_estado_civil'].' '.$linea['estado_civil']; ?>

                                                </div>
</div>

                </div>


    <div class="modal-footer">

      <button class="modal-close btn waves-effect waves-light grey">CANCELAR</button>

      <a href="config_eliminar_estado_civil.php?id_estado_civil=<?php print($linea['id_estado_civil']); ?>">
      <button class="modal-close btn waves-effect waves-light red" type="submit" name="eliminar">ELIMINAR</button></a>
                
                </div>
        </div>
<!-- FIN ELIMINAR REGISTRO CON VENTANA MODAL -->

ventana modal modal para modificar registros

ventana_modal_modificar.php


PHP:
<!-- EDITAR REGISTRO CON VENTANA MODAL -->
  <div  class="modal" id="modal2">
    <div class="modal-content">
      <h4>Modificar Registro</h4>

        <form class="col s12" method="POST" action="config_modificar_estado_civil.php?id_estado_civil=<?php echo $linea['id_estado_civil']; ?>">
        
             <br>

<div class="row">
            <div class="input-field col s12">
            <input class="black-text" type="text" name="estado_civil" value="<?php echo $linea['estado_civil']; ?>">
            <label for="password">Estado Civil</label>
            </div>
</div>

    

    </div>


 <div class="modal-footer">

    
 <button class="modal-close btn waves-effect waves-light grey">CANCELAR</button>
      <a href="config_modificar_estado_civil.php?id_estado_civil=<?php print($linea['id_estado_civil']); ?>">
      <button class="modal-close btn waves-effect waves-light blue" type="submit" name="modificar">MODIFICAR</button></a>
</form>



    </div>
  </div>
<!-- FIN EDITAR REGISTRO CON VENTANA MODAL -->

confi para eliminar los registros

config_eliminar_estado_civil.php

PHP:
<?php
include '../conexion/conexion.php';
?>

<!-- PROCESO PARA ELIMINAR -->
<?php
  if(isset($_GET['id_estado_civil']))
  {
    
    $sql_delete = $DB_con->prepare('DELETE FROM estado_civil WHERE id_estado_civil =:id_estado_civil');
    $sql_delete->bindParam(':id_estado_civil',$_GET['id_estado_civil']);
    $sql_delete->execute();
    
       $errMSG = "¡ Atención: El Registro a sido Eliminado !";

     }

?>
<!-- FIN PROCESO PARA ELIMINAR -->


config_modificar_estado_civil.php

PHP:
<?php
include '../conexion/conexion.php';
?>

<!-- proceso para actualizar -->
<?php
if(isset($_GET['modificar'])){
$sql=$DB_con->prepare("UPDATE estado_civil SET estado_civil=:estado_civil WHERE id_estado_civil=:id_estado_civil");
$sql->bindParam(':estado_civil',$_GET['estado_civil']);
$sql->bindParam(':id_estado_civil',$_GET['id_estado_civil']);
$sql->execute();
if($sql)
  {

         $successMSG = "¡ Bien Hecho: Registro actualizado Correctamente !";

     }

     else

      {

         $errMSG = "¡ Ups Aviso: El Registro no se pudo actualizar !";

     }
  }
?>
<!-- fin proceso para actualizar   -->
 

¡Regístrate y comienza a ganar!

Beneficios

  • Gana dinero por participar
  • Gana dinero por recomendarnos
  • Descubre ofertas de empleo diariamente
  • Negocios seguros
  • ¡Información premium y más!

Acceder

¿Ya tienes una cuenta? Accede aquí

Arriba