miércoles, 29 de enero de 2014

ELIMINAR REGISTROS DE UNA TABLA EN MYSQL


master.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<div>
<?php
include_once ("cabe.php");
?>
</div>
<div style="height:450px;width:100%">
<table border="0px" width="100%">
    <tr>
        <td colspan="2">
            <center><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=1'>INICIO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=2'>REGISTRO</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=3'>LISTAR</a>
            <a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=6'>EDITAR</a><a style="border: solid #000 1px; padding:5px; margin-left:10px" href='?id=7'>ELIMINAR</a></center>
        </td>
    </tr>
    <tr>
        <td width="200px" height="450px">
            <?php
            include_once ("Registros.php");
            ?>
        </td>
        <td>
            <?php
                switch($_GET['id']){
                    case 1:
                        include_once ("contenido.php");
                    break;
                    case 2:
                        include_once ("Registrar.php");
                    break;
                    case 3:
                        include_once ("Reporte.php");
                    break;
                    case 4:
                        include_once("Filtro.php");
                    break;
                    case 5:
                        include_once("Insertar.php");
                    break;
                    case 6:
                        include_once("Actualizar.php");
                    break;
                  
                }
                ?>
        </td>
    </tr>
</table>
</div>
</div>

<br>
<br>
<br>
<br>
<?php
include_once ("pi.php");
?>
<div>
</body>
</html>
cabe.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1> BASE DE DATOS AGENDA </h1></center>
</body>
</html>
Registros.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<form action="dc.php" method="POST">
        <label for="username"><h2>Usuario</h2></label>
        <input id="username" type="text" name="username" size="20" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
        <label for="passwd"><h2>Contraseña</h2></label>
        <input id="passwd" type="password" name="password" size="20" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/>
        <br>
        <br>
    <input type="submit" name="Submit" class="button" value="INGRESAR" />
</form>
</body>
</html>
contenido.php
 <html>
<head>
</head>
<body bgcolor text="blue">
<div style="width:100%; height:100%; background:url('agenda.jpg')">
   
</div>
</body>
</html>
Registrar.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=5" method="POST">
  <fieldset>
  <p>
        <label for="codigo">Codigo</label>
        <input id="codigo" type="text" name="codigo" size="18" value="<?php if (isset($_SESSION["codigo"])){echo $_SESSION["codigo"];}?>"/>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="apellido">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
    <p>
        <label for="edad">Edad</label>
        <input id="edad" type="text" name="edad" size="18" value="<?php if (isset($_SESSION["edad"])){echo $_SESSION["edad"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>
    <p>   
       <label for="ciudad">Ciudad   
       <select name="ciu">
       <option value="Azogues">Azogues
        <option value="Biblian">Biblian
         <option value="Cañar">Cañar
       </select>
       </label>      
    </p>
        <p>   
            <label for="ciudad">Sexo
       <select name="sex">
       <option>M
        <option>F
       </select>
       </label>   
    </p>
        <input type="submit" name="b2" class="button" value="INGRESAR" /> </center>
    </p>
  </fieldset>
</form>
</body>
</html>
  Reporte.php
 <html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Reportes</title>
</head>
<body>
<form action="master.php?id=4" method="POST">
  <fieldset>
    <p>       
       <label for="username">FILTRAR POR:</label>
    </p>
   
    <p>
        <label for="username">Nombre</label>
        <input id="nombre" type="text" name="nombre" size="18" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/>
    </p>
   
    <p>
        <label for="passwd">Apellido</label>
        <input id="apellido" type="text" name="apellido" size="18" value="<?php if (isset($_SESSION["apellido"])){echo $_SESSION["apellido"];}?>"/>
    </p>
        <p>
        <label for="correo">Direccion</label>
        <input id="direccion" type="text" name="direccion" size="18" value="<?php if (isset($_SESSION["direccion"])){echo $_SESSION["direccion"];}?>"/>
    </p>
    <p>
        <label for="correo">Telefono</label>
        <input id="telefono" type="text" name="telefono" size="18" value="<?php if (isset($_SESSION["telefono"])){echo $_SESSION["telefono"];}?>"/>
    <p>   
       <input type="radio" name="b3" value="1" class="imputradio" checked /><label for="username">ASENDENTE</label>
        <br>
        <input type="radio" name="b3" value="2" class="imputradio"/><label for="username">DESENDENTE</label>
    </p>
    <p>
        <input type="submit" name="b2" class="button" value="FILTRAR" /> <input type="submit" name="b1" class="button" value="LISTAR TODO" /></center>
    </p>
  </fieldset>
</form>
</body>
</html>
Filtro.php
 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    $order="asc";
    if (isset($_POST['b3'])){
        if ($_POST['b3']=="2")
            $order="desc";
    }
    $activo=false;
    if (isset($_POST['b2'])){
        $value=$_POST['nombre'].$_POST['apellido'].$_POST['direccion'].$_POST['telefono'];
        $sql=mysql_query("select * from agenda where concat(Nombre,Apellido,Direccion,telefono) like concat('%','$value','%') order by Nombre $order");
        $activo=true;
    }
    if (isset($_POST['b1'])){
        $sql=mysql_query("select * from agenda order by Nombre $order");
        $activo=true;
    }   
    if (isset($_POST['b4'])){
       
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $datos="insert into agenda values(9,'$nom','$ape',99,'$tel','$dir')";
        mysql_query($datos) or die("No se puede grabar");
        echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
    }
    if ($activo==true){
        echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=3" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
Insertar.php 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
session_start();
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
{
die ('No se establecio la conexion'.mysql_error());
}
else
{
    mysql_select_db("bddagenda",$conexion);
    if (isset($_POST['b2'])){
        $cod=$_POST['codigo'];
        $nom=$_POST['nombre'];
        $ape=$_POST['apellido'];
        $dir=$_POST['direccion'];
        $tel=$_POST['telefono'];
        $eda=$_POST['edad'];
        $ciu=$_POST['ciu'];
        $sex=$_POST['sex'];
        $sql=mysql_query("select *from agenda where idagenda=$cod");
        if($fila=mysql_fetch_array($sql)){
            $datos="update agenda set Nombre='$nom',Apellido='$ape',edad=$eda,telefono='$tel',Direccion='$dir',Ciudad='$ciu',Sexo='$sex' where idagenda=$cod";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }else
        {
            $datos="insert into agenda values($cod,'$nom','$ape',$eda,'$tel','$dir','$ciu','$sex')";
            mysql_query($datos) or die("No se puede grabar");
            echo "EL REGISTRO SE CUMPLIO EXITOSAMENTE...BY OK";
        }
    }
    echo "<br><br><br>";
}
?>
<form action="master.php?id=2" method="POST">
    <center><input type="submit" name="Submit" class="button" value="REGRESAR" /></center>
</form>
</body>
</html>
pi.php
<html>
<head>
<title> Pie </title>
</head>
<body bgcolor text="blue">
<hr>
<center><h1 style="text-align:right"> Alexandra Maguana </h1></center>
</body>
</html>
Actulizar.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
   {
    die ('No se establecio la coneccion'.mysql_error());
   }
   else
   {
     echo("");
   }
    echo "<br>";
  
  mysql_select_db("bddagenda",$conexion);

  $sql=mysql_query("select *from agenda");
  echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td><td>CIUDAD</td><td>SEXO</td><td>ACCION</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            $id=$fila['idagenda'];
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "<td>".$fila['Ciudad'],''."</td>";
            echo "<td>".$fila['Sexo'],''."</td>";
            echo "<td>"."<a href='?id=2&ida=$id'>"."Editar"."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    echo "<br><br><br>";
?>


Eliminar.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$conexion=mysql_connect("localhost","coneccionbdd","admin");
if(!$conexion)
   {
    die ('No se establecio la coneccion'.mysql_error());
   }
   else
   {
     echo("<br>");
   }
    echo "<br>";
  
   mysql_select_db("bddagenda",$conexion);
 
  if (isset($_GET['ida'])){
    $codigo=$_GET['ida'];
    $datos="delete from agenda where idagenda=$codigo";
    mysql_query($datos) or die("No se puede eliminar");
    echo "LA ELIMINACION SE CUMPLIO EXITOSAMENTE...BY OK";
  }
  $sql=mysql_query("select *from agenda");
  echo "<center><table border='1'><tr><td>ID</td><td>NOMBRE</td><td>APELLIDO</td><td>EDAD</td><td>TELEFONO</td><td>DIRECCIÓN</td><td>CIUDAD</td><td>SEXO</td><td>ACCION</td></tr>";
        while($fila=mysql_fetch_array($sql))
        {
            $id=$fila['idagenda'];
            echo "<tr>";
            echo "<td>".$fila['idagenda'],''."</td>";
            echo "<td>".$fila['Nombre'],''."</td>";
            echo "<td>".$fila['Apellido'],''."</td>";
            echo "<td>".$fila['edad'],''."</td>";
            echo "<td>".$fila['telefono'],''."</td>";
            echo "<td>".$fila['Direccion'],''."</td>";
            echo "<td>".$fila['Ciudad'],''."</td>";
            echo "<td>".$fila['Sexo'],''."</td>";
            echo "<td>"."<a href='?id=8&ida=$id'>"."Eliminar"."</td>";
            echo "</tr>";
        }
        echo "</table></center";
    echo "<br><br><br>";
?>
Confirmar.php
<html>
<head>
<title>BorrarCookie</title>
</head>
<body>
<form action="Eliminar.php" method="post">
<h1> Desea eliminar el campo seleccionado</h1>
    <br>
    <br>
    <br>
    <br>
   <p>
        <label for="Si">SI</label>
        <input type="radio" name="opcion" value="SI">
        <br>
        <label for="No">NO</label>
        <input type="radio" name="opcion" value="SI">
    </p>
    <br>
    <br>
<input type="submit" value="CONFIRMAR">
</form>
</body>
</html>
 
EJECUCIÓN
Al iniciar con el servidor nos aparece esta ventana. 



Al selecionar una de las opciones que se encuentran el boton INICIO nos muestra la pantalla principal y REGISTRO muestra la siguiente ventana donde llenamos sus campos y pulsamos INGRESAR.

 
Si el ingreso fue correcta nos muestra el siguiente pantalla.
 El boton listar nos muestra la sguiente ventana  donde podemos asignar el campo por el cual desea filtrar ya sea en orden asendente y desendente.
 El boton listar nos muestra todos los registros.
 El boton filtrar para ello tenemos que llenar el campo por el cual deseamos filtrar por ejem:por el nombre que empiecen con Mar nos da el siguiente resultado.

Al seleccionar ACTULIZAR nos muestra el siguiente formulario  con todos los registros.


Al pulsar en la pate derecha de la tabla en EDITAR  nos muestra el siguiente formulario con el registro que se ha seleccionado .
 Editamos los campos que deseamos y pulsamos  guardar.

Si se guarda correctamente nos muestra el siguiente mensaje.
 

Para verificar que se haya modificado vamos a INFORMES y listar todo y nos muestra esta ventana con todos los registros.
 Al seleccionar ELIMINAR nos muestra el siguiente formulario  con todos los registros.


Al pulsar en la pate derecha de la tabla en ELIMINAR  nos muestra el siguiente formulario con dos opciones que tenemos que seleccionar SI y  NO .
 Si seleccionamos SI y precionamos confirmar nos muestra la siguiente tabla ya con el registro eliminado.


No hay comentarios:

Publicar un comentario