miércoles, 22 de enero de 2014

INSERTAR REGISTROS EN UNA TABLA DE BDD.


master.php
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Formulario de validación de usuario</title>
</head>
<style type="text/css">
* {
 padding:0px;
 margin:0px;
}

#header {
 margin:auto;
 width:800px;
 font-family:arial;
}

ul, ol {
 list-style:none;
}

.nav li a {
 background-color:#069;
 color:#FFFFFF;
 text-decoration:none;
 padding: 10px 15px;
 display:block;
}

.nav li a:hover {
 background-color:#FF3300;
}

.nav > li {
 float:left;
}

.nav li ul {
 display:none;
 position:absolute;
 min-width:140px;
}

.nav li:hover > ul {
 display:block;
}

.nav li ul li {
 position:relative;
}

.nav li ul li ul {
 right:-140px;
 top:0px;
}
</style>
<div>
<?php
include_once ("cabe.php");
?>
</div>
<div style="height:450px;width:100%">
<table border="0px" width="100%">
    <tr>
        <td colspan="2">
            <center>
            <div id="header">
             <ul class="nav">
                 <li><a href="?id=1">Inicio</a></li>
                 <li><a href="#">Registros</a>
                 <ul>
                    <li><a href="?id=2">Insertar</a></li>
                    <li><a href="?id=6">Actualizar</a></li>
                    <li><a href="?id=7">Eliminar</a></li>
                   </ul>
                 </li>
                 <li><a href="?id=3">Listar</a></li>
             </ul>
            </div>
        </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;
                    case 7:
                        include_once("Eliminar.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'];
        $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>
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 pulzar en acctualizar nos muestra la siguiente ventana donde seleccionamos el campo que deseamos editar.
Al pulsar editar nos muetra el siguiente formulario ya com los campos que deseamos editar.
 
Editamos los campos que deseamos y pulsamos guardar.

 Y si se guarda nos muestra los siguiente mensaje.
Para verificar si esta el registro actualizado vamos a listar y mostrar todo.




No hay comentarios:

Publicar un comentario